触摸开始 [英] touchesBegan with delay

查看:95
本文介绍了触摸开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView的子类,并添加了touchesBegantouchesEnd方法...

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

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

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.

工作正常,但速度很慢.点击视图,需要0.5-1.0秒,直到我看到绿色.

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

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

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

推荐答案

尝试一下:

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];
    }
}

注意: 它将更快地工作.

这篇关于触摸开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆