ios – touchesBegan延迟

前端之家收集整理的这篇文章主要介绍了ios – touchesBegan延迟前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个UIView的子类,并添加了touchesBegan和touchesEnd方法……

在touchesBegan中,我通过在touchesEnd中使用self.backgroundColor = [UIColor greenColor] …将backgroundColor从白色设置为绿色,并将颜色重置为白色.

它工作但很慢.通过点击视图,它需要0.5 – 1.0秒,直到我看到绿色.

在UITableView中选择一个单元格要快得多.

解决方法

试试这个:
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];
    }
}

注意:它会更快地工作.

原文链接:https://www.f2er.com/iOS/331343.html

猜你在找的iOS相关文章