Manesh Manesh - 1 month ago 12
iOS Question

ALL UIButton's delay executing block

My project has

UIButtons
which are taking up to 1 second to execute the block of code.

I have buttons in other projects working fine, but for some odd reason, this project has an annoying delay.

The buttons are dailer numbers, so they need to be pressed quickly:
Heres an example of one:

- (IBAction)phonePressed:(id)sender {
UITapGestureRecognizer *backspaceGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backspace)];
UIButton *one = [[UIButton alloc] initWithFrame:CGRectMake(menuShadowLayer2.frame.origin.x+10, menuShadowLayer2.frame.origin.y+10, 80, 80)];
one.layer.cornerRadius = 40;
one.layer.borderColor = [UIColor lightGrayColor].CGColor;
one.layer.borderWidth = 1;
[one setBackgroundColor:[UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.3]];
[one setTitle:@"1" forState:UIControlStateNormal];
[one.titleLabel setTextAlignment:NSTextAlignmentCenter];
[one setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[one.titleLabel setFont:[UIFont fontWithName:@"STHeitiSC-Light" size:50]];
[container addSubview:one];
[one addGestureRecognizer:tap1];
...

- (void)dailed1 {
numberDailed.text = [numberDailed.text stringByAppendingString:@"1"];
NSLog(@"1");
}


Here is another button using UIControlEventTouchUpInside, which is just as slow if not slower.

UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(numberDailed.frame.origin.x, numberDailed.frame.origin.y+200, numberDailed.frame.size.width+40, 110)];
cancel.layer.cornerRadius = 15;
[cancel setImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
cancel.clipsToBounds = YES;
[container addSubview:cancel];
[cancel addTarget:self
action:@selector(clearNumber:)
forControlEvents:UIControlEventTouchDown];
...

-(IBAction)clearNumber:(id)sender{
[numberDailed setText:@""];
}


I have used a
UITapGestureRecognizer
as using the Button
UIControlEventTouchUpInside
or
TouchDown
was even slower.

When pressing this button (
one
), I have to wait around half a second to a second before tapping again. This obviously creates frustration when your entering a number and half of the numbers haven't been added to the string.

I have set the
UIScrollView
to
delaysContentTouches = NO;

The button highlights immediately. It simply wont execute the code straight away.
I have used button
one
as an example, but this applies to ALL
UIButtons
in my project.
Thoughts?

Answer

The problem turned out to be with the MapBox API(Not Recommended) in my project, removing this sped everything up. All code was fine, have gone back to performing selector and removed the gestures.

Comments