ios 滚动视图响应touchesBegin,touchesEnd等方法

本文介绍了一个在iOS应用中遇到的常见问题,即某些能够滚动的UI控件无法响应 touchesBegin 和 touchesEnd 方法。通过创建一个自定义的TextView类并重写这些方法,可以解决该问题。实例演示了如何实现这一解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

能够滚动的控件都不会响应touchesBegin,touchesEnd等方法,这就需要对这个类进行封装

以UITextView为例

1,创建CustomTextView类,继承与UITextView

2,在CustomTextView.m文件中重写touchesBegin,touchesEnd等方法

3,代码如下:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.dragging) {
        [[self nextResponder] touchesBegan:touches withEvent:event];
    }
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.dragging) {
        [[self nextResponder] touchesEnded:touches withEvent:event];
    }
}

转载于:https://www.cnblogs.com/shidaying/p/3838179.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值