我正在尝试在触摸并按住图像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];
}
不确定这会影响什么,但是Image View是在程序运行后通过编程创建的,而不是在加载时。感谢您的帮助,我们非常感激。
此外,我已经查看了以下链接: