iPhone - UIScrollView 和 UIDatePicker 滚动冲突:一个干扰

iPhone - UIScrollView and UIDatePicker scrolling conflict : the one interfer with the second(iPhone - UIScrollView 和 UIDatePicker 滚动冲突:一个干扰第二个)
本文介绍了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 滚动冲突:一个干扰第二个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Restoring Scroll Position in Paging Library 3(恢复分页库3中的卷轴位置)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)