简体   繁体   中英

UIPickerView with Tap Recognizer Fails

I have a UIView subclass that contains a UIPickerView. The pickerview has a tap gesture recognizer attached. The idea is that users should be able to tap the pickerview once a row is selected. This worked previously, but after making some changes it is no longer working, and I've spent a day on it and am stuck.

The UIView is initialized like this:

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];
}

The picker displays the rows and scrolls correctly. However, the tap gesture does not call its action. Suggestions?

Is your UIView userInteractionEnabled?

You might wanna look at this , Dismissing UIPickerView on tapping background

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM