IOS/Objective-C:使用 HitTouch 将 ScrollView 上的触摸事件传递到下方查看 [英] IOS/Objective-C: Pass Touch Event on ScrollView to View Below using HitTouch

查看:36
本文介绍了IOS/Objective-C:使用 HitTouch 将 ScrollView 上的触摸事件传递到下方查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个错误,无法识别只能通过滚动到达的文本视图底部区域的触摸.使用可视化调试器,我发现滚动视图挡住了视图的底部.关于 SO 和一些 Apple 文档的许多问题以及

解决方案

这个方法属于一个 UIView,你需要继承你的 UIScrollView.在根视图中的每次触摸时都会调用此方法.在我的测试中,这个方法总是被调用两次.

请考虑,来自文档:

此方法会忽略隐藏的、已禁用用户交互或 alpha 级别小于 0.01 的视图对象.此方法在确定命中时不考虑视图的内容."

I have a bug where touches to the bottom area of a textview that can only be reached by scrolling are not being recognized. Using the visual debugger, I discovered that a scrollview was blocking the bottom of the view. A number of questions on SO and some Apple docs and this excellent article here suggest when you have a view blocking one below, you need to implement some version of the following method:

  - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"hit test firing");
    UIView *hitTestView = [super hitTest:point withEvent:event];
    if (hitTestView == self) {
        hitTestView = nil;
    }
    return hitTestView;
}

-

I have gotten confused, however, on when this method fires and also what views are what. In the above code, where would I specify that scrollview is the blocking my textview? Also I get the error with the above code: No visible interface declares the selector hitTestPointWithEvent

Thanks for any suggestions. Here is image in visual debugger. Are in blue is not receiving touch (tap) events.

解决方案

This method belongs to a UIView, you would need to subclass your UIScrollView. This method is called on every touch within the root view. In my tests this method was called always twice.

Please consider, from the doc:

"This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the view’s content into account when determining a hit."

这篇关于IOS/Objective-C:使用 HitTouch 将 ScrollView 上的触摸事件传递到下方查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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