美文网首页Swiftui
iOS长按手势手指移动实时坐标获取笔记

iOS长按手势手指移动实时坐标获取笔记

作者: 数字d | 来源:发表于2021-11-11 21:13 被阅读0次

    业务场景:微信给好友发语音,长按录制,移动上滑取消
    代码实现
    给imageView添加长按手势

            imageView.userInteractionEnabled = YES;
            UILongPressGestureRecognizer * tap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(yzLongPressAction:)];
            tap.delegate = self;
            [imageView addGestureRecognizer:tap];
    

    手势内部的操作处理

    -(void)yzLongPressAction:(UILongPressGestureRecognizer *)tap {
        if (tap.state == UIGestureRecognizerStateEnded) {
            self.speakView.hidden = YES;
            self.basicView.hidden = NO;
            CGPoint point = [tap locationInView:_basicView];
            if (point.y < 0) {
                self.cancelRecoderBlock();
            }else {
                self.endRecoderBlock();
            }
        }else if(tap.state == UIGestureRecognizerStateBegan){
            self.speakView.hidden = NO;
            self.basicView.hidden = YES;
            self.startRecoderBlock();
        }else if (tap.state == UIGestureRecognizerStateChanged){
            CGPoint point = [tap locationInView:_basicView];
            NSLog(@"%@",NSStringFromCGPoint(point));
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS长按手势手指移动实时坐标获取笔记

        本文链接:https://www.haomeiwen.com/subject/ybigzltx.html