在我的viewDidLoad中,我有以下内容:
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 5;
longpressGesture.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:longpressGesture];
[longpressGesture release];
我创建了以下内容:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete Record?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Yes",@"No",nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
使用模拟器,当我长按时,会显示两个操作表而不是一个。
关于为什么会这样的任何想法?
这是模拟器的问题吗?
答案 0 :(得分:2)
这对模拟器来说不是问题。
当手势经历不同的状态(开始,结束等)时,会多次调用手势处理程序。
您需要在处理程序方法中检查手势state
:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
if (sender.state == UIGestureRecognizerStateBegan)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
[actionSheet showInView:self.view];
[actionSheet release];
}
}