iPhone - UIScrollView and UIDatePicker scrolling conflict : the one interfer with the second

后端 未结 2 1629
Happy的楠姐
Happy的楠姐 2020-12-19 19:00

I have a UIDatePicker inside a UIScrollView. But the UIDatePicker does not respond to scroll touches. It\'s the scrollview that is scrolling. Reading some docs on the net, I

相关标签:
2条回答
  • 2020-12-19 19:11

    Combine @ Oliver's answer with this one for keyboard text hiding issues, and you've got one awesome class for scroll view's.

    http://github.com/webartisan/TPKeyboardAvoiding

    Love Stackoverflow!!!!

    Thanks.

    0 讨论(0)
  • 2020-12-19 19:26

    Solved using that post : http://www.alexc.me/uiscrollview-and-uidatepicker/153/

    Just make the class with that code inside it :

    UIScrollViewBreaker.h

    @interface UIScrollViewBreaker : UIScrollView {
    
    }
    
    - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;
    - (BOOL)touchesShouldCancelInContentView:(UIView *)view;
    
    @end
    

    UIScrollViewBreaker.m

    @implementation UIScrollViewBreaker
    
    
    - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
    
        if ([view isKindOfClass:[UIDatePicker class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
            //|| [view isKindOfClass:[UIPicker class]]
            return YES;
        }
        return [super touchesShouldBegin:touches withEvent:event inContentView:view];
    }
    
    - (BOOL)touchesShouldCancelInContentView:(UIView *)view {
        if ([view isKindOfClass:[UIDatePicker class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
            return NO;
        }
        return [super touchesShouldCancelInContentView:view];
    }
    
    
    @end
    

    And in IB, set the class of the UIScrollView to UIScrollViewBreaker.

    And it's done.

    Just don't forget to let some place on the view for the user to let him scroll the scrollview.

    0 讨论(0)
提交回复
热议问题