iPhone 应用程序中的 uigesturerecognizer

发布于 2024-12-12 18:48:34 字数 503 浏览 0 评论 0原文

您好,我想模拟长按按钮吗?我该怎么做?我认为需要一个计时器。你能帮助我吗?我看到 UILongPressGestureRecognizer 但如何利用这种类型?

这是代码,它不识别长按

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

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

Hello I want to emulate a long a press button? how can I do this? I think a timer is needed. Can you help me? I see UILongPressGestureRecognizer but how can I utilize this type?

here is the code , it isn't recognize long press

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-12-19 18:48:34

为了使用UILongPressGestureRecognizer,您必须设置minimumPressDuration属性。这指定了手势识别器被触发之前等待的时间。例如

UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)] autorelease];
longPress.minimumPressDuration = 2.0f;
[self.button addGestureRecognizer:longPress];

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

In order to utilize UILongPressGestureRecognizer you must set the minimumPressDuration property. This specifies how long to wait until your gesture recognizer is fired. For example

UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)] autorelease];
longPress.minimumPressDuration = 2.0f;
[self.button addGestureRecognizer:longPress];

- (void)longPress:(UILongPressGestureRecognizer*)gesture {
    if ( gesture.state == UIGestureRecognizerStateEnded ) {
         NSLog(@"Long Press");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文