UIButton长新闻活动 [英] UIButton Long Press Event

查看:142
本文介绍了UIButton长新闻活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模仿一个长按按钮,我该怎么做?我认为需要一个计时器。
我看到 UILongPressGestureRecognizer 但我该如何使用这种类型?

I want to emulate a long a press button, how can I do this? I think a timer is needed. I see UILongPressGestureRecognizer but how can I utilize this type?

推荐答案

您可以通过创建 UILongPressGestureRecognizer 实例并将其附加到按钮开始。

You can start off by creating and attaching the UILongPressGestureRecognizer instance to the button.

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.button addGestureRecognizer:longPress];
[longPress release];

然后实现处理手势的方法

And then implement the method that handles the gesture

- (void)longPress:(UILongPressGestureRecognizer*)gesture {
    if ( gesture.state == UIGestureRecognizerStateEnded ) {
         NSLog(@"Long Press");
    }
}

现在这将是基本方法。您还可以设置印刷机的最短持续时间以及可容忍的误差范围。并且还要注意,如果你在识别出手势之后几次调用该方法,那么如果你想在它结束时做一些事情,你将必须检查它的状态并处理它。

Now this would be the basic approach. You can also set the minimum duration of the press and how much error is tolerable. And also note that the method is called few times if you after recognizing the gesture so if you want to do something at the end of it, you will have to check its state and handle it.

这篇关于UIButton长新闻活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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