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

标签 iphone

我已将 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/

相关文章:

iphone - 传递 UIColor 作为参数时崩溃

iphone - iOS 缓存策略

ios - 将键/值存储在 NSDictionary/NSCache 中,它保留数据直到应用程序终止

iphone - NSMutableURLRequest 和 NSURLConnection 无法在 GCDdispatch_async 中工作?

iphone - MKMapViewDelegate + JSON Alamofire

iphone - 将 NSDictionary 解析为带有自定义分隔符的字符串

objective-c - 如何在 UIImageView 中显示 base64 图像?

iphone - 如何在 iphone 的 uitableview 中只显示前 5 个单元格

iphone - 如何隐藏 iOS 数字键盘

objective-c - NSString:isEqual 与 isEqualToString