One solution would be to create a subclass of UIPickerView and override the touchesEnded:withEvent:
method:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
// dismiss the picker view here, either directly, or you could notifiy
// the delegate with a custom message:
if ([self.delegate respondsToSelector:@selector(pickerViewShouldDismiss:)]) {
[self.delegate pickerViewShouldDismiss:self];
}
}
Or you could add a UITapGestureRecognizer
to the UIPickerView
:
UITapGestureRecognizer *tapGR = [UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(pickerViewTapped];
[pickerView addGestureRecognizer:tapGR];
And then:
- (void)pickerViewTapped {
// dismiss the picker.
}
I'm not 100% sure though this won't interfere with the way UIPickerView
handles taps.