gpt4 book ai didi

iphone - UIPickerView 添加到 UIScrollView 时不滚动!

转载 作者:行者123 更新时间:2023-12-03 19:12:14 31 4
gpt4 key购买 nike

我已将 UIPickerView 添加到 UIScrollView 但现在 UPickerView 不滚动。当我将它添加到 self.view 时,它滚动顺畅。这是我的代码

monthsArray = [[NSArray alloc] initWithObjects:@"Jan",@"Feb",@"Mar",@"Apr",@"May",@"Jun",@"Jul",@"Aug",@"Sep",@"Oct",@"Nov",@"Dec",nil];

UIPickerView *objPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(185,350,100,100)];
objPickerView.userInteractionEnabled=YES;
objPickerView.delegate = self;
objPickerView.showsSelectionIndicator = YES;
[objScrollView addSubView:objPickerView];

我已经包含了委托(delegate)及其方法。看看这个问题。提前致谢。
如果我不清楚,请告诉我。

最佳答案

我使用 UIPickerView 的子类来达到相同的目的,但我的要简单得多:

@implementation ScrollablePickerView

- (UIScrollView *)findScrollableSuperview {

UIView *parent = self.superview;
while ((nil != parent) && (![parent isKindOfClass:[UIScrollView class]])) {
parent = parent.superview;
}
UIScrollView* scrollView = (UIScrollView *)parent;

return scrollView;
}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event {
UIScrollView* scrollView = [self findScrollableSuperview];

if (CGRectContainsPoint(self.bounds, point)) {
scrollView.canCancelContentTouches = NO;
scrollView.delaysContentTouches = NO;
} else {
scrollView.canCancelContentTouches = YES;
scrollView.delaysContentTouches = YES;
}

return [super hitTest:point withEvent:event];
}

@end

就像一个魅力 - 至少对我来说。

关于iphone - UIPickerView 添加到 UIScrollView 时不滚动!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4793535/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com