【发布时间】:2014-07-15 13:29:30
【问题描述】:
当我触摸并按住图像 2 秒钟时,我试图调用一个警告框。这是我到目前为止得到的:
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *tapAndHoldGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAndHoldGesture:)];
tapAndHoldGesture.minimumPressDuration = 0.1;
tapAndHoldGesture.allowableMovement = 600;
[self.view addGestureRecognizer:tapAndHoldGesture];
}
- (void) handleTapAndHoldGesture:(UILongPressGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
return;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Gesture:" message:@"hold it" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
不确定这是否会产生任何影响,但图像视图是稍后以编程方式创建的,而不是在加载时创建的。提前感谢您的任何帮助..
另外,我查看了以下链接:
Long press gesture on UICollectionViewCell
【问题讨论】:
-
您在哪里向 imageView 添加手势?我只能看到处理程序方法
-
我的错误......在viewDidLoad中。谢谢。
标签: ios objective-c touch gestures