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

断了今生、忘了曾经 提交于 2019-11-28 05:24:21

问题


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've set "Delay Content Touches" to NO, an now I see the datepicker starting a slight scroll, but it's still the scrollview that take the final word. I have some place on the screen where the user can touch to scroll the view. So how may I separate the two kind of scrolls ans make the datepicker scroll in a normal way ?

Thank you for your help


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4709124/iphone-uiscrollview-and-uidatepicker-scrolling-conflict-the-one-interfer-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!