How to disable browsing when using UIPickerView

I used UIPickerView , my question is simple, how to turn off the view when showing the picker view, so that we can guarantee that the user does not change anything. I tried with the setuserInteractinEnabled : method, but it also disables the viewer. Any idea ..?

+4
source share
5 answers

I needed to do something similar and subclass the UIActionSheet to add a selection view to it. While the action sheet is complete, you cannot interact with the main views.

Here you can find some examples on how to add a UIPickerView to a UIActionSheet , for example how to add a UIPickerView to a UIActionSheet

+1
source

You have several options:

  • Display the picker in the popup menu if you are using iPad : Popover
  • Display it in the action sheet (UIActionSheet) if you are using an Iphone: Action Table
  • Display the collector using the current modal controller.

These 3 options can block touch events of the parent view.

+1
source

I usually add an extra UIView with 50% transparency and a black background - and this solves three problems:

  • Custom view (pickerview or any other user input fields)
  • Dimmed background - for the user to notice what needs to be done
  • User interaction is only available for text input / input / etc
+1
source

Take one UIView to name viewBack, as shown below.

 @interface ViewController : UIViewController{ UIView *viewBack; } 

in viewDidLoad: method simply defines this viewBackwith frame ie

 - (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 moment on this method, a screen similar to this will appear.

 -(IBAction)btnPickerViewOpen_Clicked:(id)sender{ viewBack.hidden = NO; [self.view bringSubviewToFront:viewBack]; [self.view bringSubviewToFront:yourPickerView]; } 

when you want to hide the UIPickerView at this time, use the following thread ...

 -(IBAction)btnPickerViewClosed_Clicked:(id)sender{ viewBack.hidden = YES; // also hide pickerview with your requirement } 

Hope this helps you ...

+1
source

you just need to try @Rene Jennrich's answer .. you need to see some examples for this .. 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)]; 
0
source

Source: https://habr.com/ru/post/1441247/


All Articles