iOS 不会将触摸转发到下面的视图 [英] iOS do not forward touches to views below

查看:26
本文介绍了iOS 不会将触摸转发到下面的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有 UIScrollView,其中包含许多 UITableView.在该表的单元格中有 UISlider.如果用户在表格视图上进行滚动手势,我如何禁用触摸转发?现在,如果用户在滑块附近(但不在滑块上)做出滚动手势,则触摸事件将转发到滚动视图.

In my app I have UIScrollView which has many UITableViews. In cells of this table there is UISlider. How I can disable touch forwarding if user make scroll gesture on table view? Now if user make scroll gesture near slider (but not on it) the touch event gets forwarder to scroll view.

推荐答案

您可以继承 UIScrollView 并将此方法添加到新类中

You can subclass UIScrollView and add this method to the new class

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    UIView *result = [super hitTest:point withEvent:event] ;
    self.scrollEnabled = ![result isKindOfClass:[UISlider class]] ;
    return result ;

} 

这篇关于iOS 不会将触摸转发到下面的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆