Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

touchesBegan with delay

I have a subclass of UIView, and added the touchesBegan and touchesEnd methods...

In touchesBegan, I set the backgroundColor from white to green by using self.backgroundColor = [UIColor greenColor] ... in the touchesEnd I reset the color to white.

It works but very slowly. By tapping the view, it takes 0.5 - 1.0 sec until I see the green color.

Selecting a cell in a UITableView it's much faster.

like image 274
Maurice Raguse Avatar asked Aug 05 '15 09:08

Maurice Raguse


1 Answers

Try this:

self.view.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(doCallMethod:)];
    recognizer.delegate = self;
    recognizer.minimumPressDuration = 0.0;
    [self.view addGestureRecognizer:recognizer];

- (void)doCallMethod:(UILongPressGestureRecognizer*)sender {
    if(sender.state == UIGestureRecognizerStateBegan){
        NSLog(@"Begin");
        self.view.backgroundColor = [UIColor greenColor];
    }else if (sender.state == UIGestureRecognizerStateEnded){
        NSLog(@"End");
        self.view.backgroundColor = [UIColor whiteColor];
    }
}

Note: It will work more faster.

like image 185
Mayur Avatar answered Oct 14 '22 12:10

Mayur