iOS中长按手势

长按手势操作只有刚开始的时候执行的是UIGestureRecognizerStateBegan事件,其他均为end手势,因此可以判断手势事件做相应的操作,如长按保存图片等。

//6.添加长按手势
    UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPressGestures:)];
    gesture.minimumPressDuration=1.0f;
    gesture.numberOfTouchesRequired = 1;
    gesture.delegate = self;
    self.qrCodeImage.userInteractionEnabled=YES;
    [self.qrCodeImage addGestureRecognizer:gesture];


- (void) handleLongPressGestures:(UILongPressGestureRecognizer *)paramSender{

    if (paramSender.state == UIGestureRecognizerStateBegan) {
        [self savePhoto];
           NSLog(@"long pressTap state :begin");

       }else {
           NSLog(@"long pressTap state :end");
       }

    NSLog(@"-------------");


}

你可能感兴趣的:(iOS中长按手势)