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

2022-11-09移动开发问题
4

本文介绍了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 滚动冲突:一个干扰第二个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End
UIScrollView

相关推荐

UIScrollView 和 Cocos2D
UIScrollView and Cocos2D(UIScrollView 和 Cocos2D)...
2024-08-12 移动开发问题
2

如何在没有 UIScrollView 的情况下放大和缩小 UIImageView?
How can i zoom in and out in a UIImageView without UIScrollView?(如何在没有 UIScrollView 的情况下放大和缩小 UIImageView?)...
2024-04-15 移动开发问题
9

iPhone SDK:UIScrollView 不滚动
iPhone SDK: UIScrollView does not scroll(iPhone SDK:UIScrollView 不滚动)...
2024-04-15 移动开发问题
11

UIScrollView 分页自动布局 &故事板
UIScrollView Paging Autolayout amp; Storyboard(UIScrollView 分页自动布局 amp;故事板)...
2023-09-12 移动开发问题
7

在 UIScrollView 的底部查看,带有 AutoLayout
View at the bottom in a UIScrollView, with AutoLayout(在 UIScrollView 的底部查看,带有 AutoLayout)...
2023-09-11 移动开发问题
1

dequeueReusableCell 打破了cliptobounds
dequeueReusableCell breaks cliptobounds(dequeueReusableCell 打破了cliptobounds)...
2023-09-09 移动开发问题
1