在UIWebView上长按手势

时间:2013-01-08 10:31:48

标签: ios uigesturerecognizer

那里。

我在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];
     }

1 个答案:

答案 0 :(得分: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];
   }
}