iPhone - UIScrollView and UIDatePicker scrolling conflict : the one interfer with the second(iPhone - UIScrollView 和 UIDatePicker 滚动冲突:一个干扰第二个)
问题描述
我在 UIScrollView 中有一个 UIDatePicker.但是 UIDatePicker 不响应滚动触摸.这是滚动的滚动视图.在网上阅读了一些文档,我将延迟内容触摸"设置为 NO,现在我看到日期选择器开始轻微滚动,但它仍然是最终决定字的滚动视图.我在屏幕上有一些地方,用户可以触摸以滚动视图.那么如何将这两种滚动分开并以正常方式使日期选择器滚动呢?
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 ?
感谢您的帮助
推荐答案
使用那个帖子解决了:http://www.alexc.me/uiscrollview-and-uidatepicker/153/一个>
只需在其中创建包含该代码的类:
Just make the class with that code inside it :
UIScrollViewBreaker.h
UIScrollViewBreaker.h
@interface UIScrollViewBreaker : UIScrollView {
}
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;
- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
@end
UIScrollViewBreaker.m
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.
And in IB, set the class of the UIScrollView to UIScrollViewBreaker.
它已经完成了.
只是不要忘记在视图上留出一些位置让用户滚动滚动视图.
Just don't forget to let some place on the view for the user to let him scroll the scrollview.
这篇关于iPhone - UIScrollView 和 UIDatePicker 滚动冲突:一个干扰第二个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone - UIScrollView 和 UIDatePicker 滚动冲突:一个干扰
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01