在我的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];
}使用模拟器,当我长按时,出现两个动作单而不是一个动作单。
有什么想法可以解释为什么会这样吗?
模拟器有问题吗?
发布于 2011-10-14 00:56:49
模拟器不是问题。
当手势经历不同的状态(开始、结束等)时,手势处理程序会被多次调用。
您需要在处理程序方法中检查手势的state:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
if (sender.state == UIGestureRecognizerStateBegan)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
[actionSheet showInView:self.view];
[actionSheet release];
}
}https://stackoverflow.com/questions/7757124
复制相似问题