iPhone - UIScrollView 和 UIDatePicker 滚动冲突 : the one interfer with the second

标签 iphone uiscrollview scroll uidatepicker freeze

我在 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/

相关文章:

html - 如何使用 HTML 和 CSS 在网站中添加不同的部分?

iOS:更改 View 的框架不起作用

ios - 使用 AutoLayout/UIScrollView 设置约束时了解 UIView 高度

ios - UIScrollView 大小问题

android - 如何在 Android RecyclerView 和 LayoutManager 中使用 scrollVerticallyBy()?

java - 滚动条上的 Jquery 下划线

iPhone 多 View 旋转 hell

iphone - 在 View 导航时在 UITableView 中显示数据

iphone - 在 iPhone 中缝合图片

iphone - NSMutableArray addObject,无法识别的选择器