I have been using UIPickerView
, my question is simple, how to disable the view when picker view is showing, so that we can ensure user are not changing anything in view. I have tried with setuserInteractinEnabled
: method but it is disabling picker view too.. Any idea..?
-
1Check out this thread might be helpful for you http://stackoverflow.com/questions/5404856/how-to-disable-touch-input-to-all-views-except-the-top-most-view – sandy Oct 22 '12 at 09:50
-
do you have any textfield to invoke your pickerview.if you have like that then disable in textfieldDidBeginEditing method.If you want to disable the whole view except pickerview then you need to disable all views separately – Dinesh Raja Oct 22 '12 at 09:50
-
@R.A No I don't have any text field, I am using button. – Newbee Oct 22 '12 at 09:57
7 Answers
I had to do something similar, and subclassed an UIActionSheet
to add a picker view to it. While the Action Sheet is up, you cannot interact with the underlying views.
You can find some examples here on SO how to add a UIPickerView
to an UIActionSheet
, like how to add UIPickerView in UIActionSheet
You have several options:
- Display the picker in a pop-up if you are using Ipad : Popover
- Display it in an action sheet (UIActionSheet) if you are using Iphone : Action sheet
- Display the picker using present modal view controller
These 3 option can block the parent view touch events.

- 103,496
- 31
- 153
- 200
Take one UIView
give name viewBack like bellow in
@interface ViewController : UIViewController{
UIView *viewBack;
}
in viewDidLoad:
method just define this viewBackwith frame i.e.
- (void)viewDidLoad
{
viewBack = [[UIView alloc] initWithFrame:CGRectMake(95, 230, 130, 40)];
viewBack.backgroundColor = [UIColor blackColor];
viewBack.alpha = 0.7f;
viewBack.layer.masksToBounds = NO;
viewBack.layer.cornerRadius = 8;
viewBack.hidden =YES;
}
when you want to show the UIPickerView
at that time on that method show up screen like this..
-(IBAction)btnPickerViewOpen_Clicked:(id)sender{
viewBack.hidden = NO;
[self.view bringSubviewToFront:viewBack];
[self.view bringSubviewToFront:yourPickerView];
}
when you want to hide the UIPickerView
at that time use bellow flow...
-(IBAction)btnPickerViewClosed_Clicked:(id)sender{
viewBack.hidden = YES;
// also hide pickerview with your requirement
}
i hope this help you...

- 20,427
- 11
- 57
- 70
I usually add extra UIView with 50% transparency and black background - and that solves three problems:
- Custom View (pickerview or any other user input fields)
- Dimmed background - so that user notices what needs to be done
- User interaction available only on pickerview/text input/etc

- 4,764
- 2
- 50
- 72
you just need to try @Rene Jennrich answer.. you need to see some examples for that..try this code if you want..
UIActionSheet *inputActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[inputActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,320,40)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[inputActionSheet addSubview:pickerToolbar];
UIPickerView fontPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 0, 0)];
fontPickerView.showsSelectionIndicator = YES;
[fontPickerView setTag:1];
[fontPickerView setDelegate:self];
[fontPickerView setDataSource:self];
[inputActionSheet addSubview:fontPickerView];
[inputActionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[inputActionSheet setBounds:CGRectMake(0, 0, 320, 485)];

- 8,501
- 5
- 42
- 81
I had the same issue. The buttons behind the UIPickerView taking action when I tapped on pickerview inside, although buttons were not visible only pickerview is visible. I had managed it using the hidden property of view on button actions. Like
@IBAction func tapPrivacyPolicy(_ sender: Any) {
if viewDatePicker.isHidden == false { // means UIPickerView is Visible
return
}
//do other work
}

- 9,221
- 1
- 66
- 58
To disable the picker from being clicked:
fooPicker.isUserInteractionEnabled = false

- 2,017
- 1
- 21
- 30