如何正确禁用 UIPickerView 组件滚动?
How to properly disable UIPickerView component scrolling?
Aster 发现自己处于想要禁用 UIPickerView 组件但没有找到任何使用默认功能但试图通过使用标签或多个 UIPickerView 绕过它的答案的情况,我开始按顺序查找 UIPickerView 结构通过使用 OS 已经存在的功能找到更直接的方法来解决问题。
所以这些是我的答案,我通过反复试验发现的,以及我使用它的方式:
方法:
- (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];
}
我希望这些能帮助那些发现自己和我处境相同的人:)
Aster 发现自己处于想要禁用 UIPickerView 组件但没有找到任何使用默认功能但试图通过使用标签或多个 UIPickerView 绕过它的答案的情况,我开始按顺序查找 UIPickerView 结构通过使用 OS 已经存在的功能找到更直接的方法来解决问题。
所以这些是我的答案,我通过反复试验发现的,以及我使用它的方式:
方法:
- (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];
}
我希望这些能帮助那些发现自己和我处境相同的人:)