gpt4 book ai didi

iphone - iphone 应用程序中的 uigesturerecognizer

转载 作者:行者123 更新时间:2023-11-29 11:19:27 26 4
gpt4 key购买 nike

您好,我想模拟长按按钮?我怎样才能做到这一点?我认为需要一个计时器。你能帮助我吗?我看到 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");
}
}

最佳答案

为了利用 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");
}
}

关于iphone - iphone 应用程序中的 uigesturerecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7966073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com