开发者

Intercept UIControlEventTouchUpInside in hitTest:withEvent:

I have followed this great tutorial and I finally managed to implement a 3 independent rows scrollable interface.

I am left with a problem though, as the key of that tutoria开发者_开发知识库l is the use of method:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 
{
    NSLog(@"in hitTest");
    if ([self pointInside:point withEvent:event]) {
        return _scrollView;
    }
    return nil;
}

in order to handle the scrolling even when outside the scrollview area. In fact my rows are filled with UIButtons and their TouchUpInside events got mixed up with hit events. Is there a way to make this method recognize those events and reject them, letting them propagate to legitimate delegate?


You should probably implement the -hitTest:withEvent: method as follows:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  UIView *superView = [super hitTest:point withEvent:event];

  if (superView == self)
    return _scrollView;

  return superView; 
}

This will allow interaction within subviews of the UIScrollView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜