IOS/Objective-C: Pass Touch Event on ScrollView to

2019-08-18 08:13发布

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.

enter image description here

1条回答
再贱就再见
2楼-- · 2019-08-18 08:29

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."

查看更多
登录 后发表回答