0

那里。

我在 self.view 中添加了一个长按手势,但遗憾的是,这个手势每次被识别时都会触发不止一次。代码已列出。每次识别手势时,都会出现 2 个操作表。

    - (void)viewDidLoad
      {
         [super viewDidLoad];
         UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
         longPress.numberOfTouchesRequired = 1;
         [self.view addGestureRecognizer:longPress];
      }


    -(void)handleLongPress:(UILongPressGestureRecognizer *)gesture
     {
        UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Hello",nil];
        [action showInView:self.view];
     }
4

1 回答 1

0

好吧,我想我应该只关心动作方法中手势的开始状态:

-(void)handleLongPress:(UILongPressGestureRecognizer *)gesture
{
   if (gesture.state == UIGestureRecognizerStateBegan) {
      UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Hello",nil];
      [action showInView:self.view];
   }
}
于 2013-01-08T10:46:20.557 回答