我在 UIScrollView 中有一个 UIDatePicker。 但 UIDatePicker 不响应滚动触摸。这是滚动的 ScrollView 。在网上阅读了一些文档,我将“延迟内容触摸”设置为“否”,现在我看到日期选择器开始轻微滚动,但它仍然是 ScrollView 来决定最终的结果。我在屏幕上有一些地方,用户可以触摸以 ScrollView 。那么我如何分离这两种滚动并使日期选择器以正常方式滚动?
感谢您的帮助
最佳答案
使用该帖子解决了: http://www.alexc.me/uiscrollview-and-uidatepicker/153/
只需在其中包含该代码即可创建类:
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
并在IB中,将UIScrollView的类设置为UIScrollViewBreaker。
就这样完成了。
只是不要忘记在 View 上留出一些位置供用户滚动 ScrollView 。
关于iPhone - UIScrollView 和 UIDatePicker 滚动冲突 : the one interfer with the second,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4709124/