UIDatePicker inside UIScrollView with pages

后端 未结 3 1036
执念已碎
执念已碎 2021-01-03 05:19

I have a UIScrollView with 2 pages, and I can scroll horizontally between them. However, on one of my pages, I have a UIDatePicker, and the scroll view is intercepting the

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 05:58

    Actually, there is a much simpler implementation than what Bob suggested. This works perfectly for me. You will need to subclass your UIScrollview if you haven't already, and include this method:-

    - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        UIView* result = [super hitTest:point withEvent:event];
    
        if ([result.superview isKindOfClass:[UIPickerView class]])
        {
             self.canCancelContentTouches = NO;  
             self.delaysContentTouches = NO;
        }
        else 
        {
             self.canCancelContentTouches = YES; // (or restore bool from prev value if needed)
             self.delaysContentTouches = YES;    // (same as above)
        }
        return result;
    }
    

    The reason I use result.superview is that the view which gets the touches will actually be a UIPickerTable, which is a private API.

    Cheers

提交回复
热议问题