带有Tap识别器的UIPickerView失败

时间:2014-05-31 07:32:56

标签: ios uipickerview

我有一个包含UIPickerView的UIView子类。 pickerview附有一个水龙头手势识别器。这个想法是用户应该能够在选择一行后点击选择器视图。这在以前有效,但经过一些改动之后它已经不再有效了,而且我已经花了一天时间在上面而且卡住了。

UIView初始化如下:

self = [super initWithFrame:frame];
if (self)
{
    [Utility NSLogRect:frame caption:@"FRAME="];
    self.backgroundColor = [UIColor whiteColor];
    self.delegate = del;
    backgroundColor = color;
    videoList = [[NSMutableArray alloc] init];
    [self initializeView];
    [self displayPicker];
}
return self;


- (void) initializeView
{
    pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f,0.0f,self.frame.size.width,self.frame.size.height)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
    pickerView.backgroundColor = backgroundColor;
    pickerView.alpha = 1.0f;
    UITapGestureRecognizer* gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerViewTapGestureRecognized:)];
    gestureRecognizer.cancelsTouchesInView = NO;
    gestureRecognizer.numberOfTapsRequired = 1;
    [pickerView addGestureRecognizer:gestureRecognizer];
    [self addSubview:pickerView];
    [self bringSubviewToFront:pickerView];
}

选择器正确显示行和滚动。但是,点击手势不会调用其动作。建议?

1 个答案:

答案 0 :(得分:1)

你的UIView是userInteractionEnabled吗?

你可能想看看这个,Dismissing UIPickerView on tapping background