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 滚动冲突:一个干扰
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
