【问题标题】:How to properly disable UIPickerView component scrolling?如何正确禁用 UIPickerView 组件滚动?
【发布时间】:2015-11-22 22:01:54
【问题描述】:

Aster 发现自己处于想要禁用 UIPickerView 组件并且没有找到任何使用默认功能但试图通过使用标签或多个 UIPickerViews 解决它的情况下,我开始在 UIPickerView 结构中寻找通过使用操作系统已经存在的功能来解决问题的更直接的方法。

【问题讨论】:

    标签: ios iphone uigesturerecognizer uipickerview uipickerviewcontroller


    【解决方案1】:

    这就是我的答案,我通过反复试验找到的,以及我使用它的方式:

    方法:

    - (void)dissableUIPickerViewComponent:(int)componentToDissable forPickerView:(UIPickerView *)pickerView{
    
        NSArray *pickerViews = [[NSArray alloc] initWithArray:[pickerView subviews]];
        UIView *mainSubview;
        for (int count = 0; count < pickerViews.count; count++) {
            UIView *temp = [pickerViews objectAtIndex:count];
            if (temp.frame.size.height > 100) {
                mainSubview = temp;
            }
    
        }
    
        NSArray *componentSubview = [mainSubview subviews];
        while ([[[[componentSubview objectAtIndex:componentToDissable] subviews] firstObject] superview].gestureRecognizers.count) {
            [[[[[componentSubview objectAtIndex:componentToDissable]subviews]firstObject]superview] removeGestureRecognizer:[[[[[componentSubview objectAtIndex:componentToDissable]subviews]firstObject]superview].gestureRecognizers objectAtIndex:0]];
        }
    
    }
    

    最佳通话地点:

    - (void)viewDidAppear:(BOOL)animated{
       [self dissableUIPickerViewComponent:0 myPickerView];
    }
    

    我希望这些可以帮助那些发现自己处于与我相同的位置的其他人:)

    【讨论】:

    • 在系统控件的视图层次结构中混混是个坏主意,并且可能会随着未来的系统更新而中断。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多