美文网首页
iOS开发-禁用UITextView中ApplePencil手写

iOS开发-禁用UITextView中ApplePencil手写

作者: 黑色幽默_0d96 | 来源:发表于2024-01-10 16:27 被阅读0次

    新建子类继承UITextView,子类需遵循UIGestureRecognizerDelegate协议

    @interface SubTextView : UITextView<UIGestureRecognizerDelegate>
    
    @end
    
    @implementation SubTextView
    
    //通过touch事件,判断是否是UITouchTypePencil
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if (touch.type == UITouchTypePencil) {
            self.editable = NO;
            return NO;
        }
        self.editable = YES;
        return YES;
    }
    
    //本次touch结束时,重置可编辑状态,
    //避免当pencil切换手指点击唤起键盘时,需要连续点两次
    - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        [super touchesEnded:touches withEvent:event];
        self.editable = YES;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS开发-禁用UITextView中ApplePencil手写

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