简体   繁体   中英

IOS/Objective-C: Pass Touch Event on ScrollView to View Below using HitTouch

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM