Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So i created a UIViewCOntroller subclass to manage this.</p> <p>on that i wrote this function to add.</p> <pre><code>-(void) addToViewWithAnimation:(UIView *) theView { UIView* myview = self.view; CGRect frame = myview.frame; frame.origin.y = 420; myview.frame = frame; UIView* bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; bgView.backgroundColor = [UIColor blackColor]; bgView.alpha = 0.6; backgroundView = bgView; [theView addSubview: bgView]; // this adds in the dark background [theView addSubview:self.view]; // this adds in the pickerView with toolbar. [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; frame = myview.frame; frame.origin.y = 420 - frame.size.height; myview.frame = frame; [UIView commitAnimations]; } </code></pre> <p>I then created the view in IB, here is what my class Header looked like at the end of that. (there is also a UItoolbar on the view i just do not have a reference to it in my Controller)</p> <pre><code>@interface PropertyPickerController : UIViewController { IBOutlet UIPickerView* Picker; IBOutlet UIButton* DoneButton; IBOutlet UIButton* CancelButton; UIView* backgroundView; NSArray* SimpleObjects; id PickerObjectDelegate; SEL PickerObjectSelector; } </code></pre> <p>To then hide the view i use.</p> <pre><code>-(void) removeFromSuperviewWithAnimation { UIView* myview = self.view; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(AnimationDidStop:)]; [UIView setAnimationDuration:0.5]; // set fram below window. CGRect frame = myview.frame; frame.origin.y = 420; myview.frame = frame; backgroundView.alpha = 0; //fades shade to nothing [UIView commitAnimations]; } -(void) AnimationDidStop:(id) object { [self.view removeFromSuperview]; //removes view after animations. [backgroundView removeFromSuperview]; } </code></pre> <p>And last but not least all the delegate functions for the picker.</p> <pre><code> - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { FBSimpleObject* object = (FBSimpleObject*)[SimpleObjects objectAtIndex:row]; return object.Name; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1;} - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [SimpleObjects count]; } - (IBAction)CancelButtonClick { [self removeFromSuperviewWithAnimation]; } - (IBAction)DoneButtonClick { //This performs a selector when the done button is clicked, makes the controller more versatile. if(PickerObjectDelegate &amp;&amp; PickerObjectSelector) { NSMethodSignature* signature = [PickerObjectDelegate methodSignatureForSelector:PickerObjectSelector]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; [invocation setTarget:PickerObjectDelegate]; [invocation setSelector:PickerObjectSelector]; [invocation setArgument:&amp;object atIndex:2]; [invocation retainArguments]; [invocation invoke]; } } </code></pre> <p>This is how you do the ToolBar. Basically i use the same concept with a ViewController subclass, and i dont use the standard push view or modal display options. (the example here actually places a Textbox and a toolbar on top of the keyboard.</p> <p>@interface BugEditCommentController : UIViewController { UITextView* Comment; UIToolbar* Toolbar; } -(void) addToViewWithAnimation:(UIView*) theView;</p> <p>To activate this view usually you would call [object becomeFirstResponder]; so if you add this to your view Controller constructor, all you need to do is call [object becomeFirstResponder];</p> <pre><code> NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil]; [nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil]; </code></pre> <p>abd if you implement this method on your controller (defined in the above code)</p> <pre><code>-(void) keyboardWillShow:(NSNotification *) note { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; CGRect toolbarFrame = Toolbar.frame; CGRect keyboardFrame; CGPoint keyboardCenter; [[note.userInfo valueForKey:UIKeyboardCenterEndUserInfoKey] getValue:&amp;keyboardCenter]; [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &amp;keyboardFrame]; //CGRect toolbarRect = Toolbar.center; toolbarFrame.origin.y= keyboardCenter.y - ((keyboardFrame.size.height/2) + (toolbarFrame.size.height)); Toolbar.frame = toolbarFrame; [UIView commitAnimations]; } -(void) keyboardWillHide:(id) object { //you could call [self removeFromSuperviewHere]; } -(void) removeFromsuperViewWithAnimation { [Comment resignFirstResponder]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(AnimationDidStop:)]; CGRect frame = Toolbar.frame; frame.origin.y = 480; Toolbar.frame = frame; [self.view viewWithTag:1].alpha = 0; //fade transparent black background to clear. [UIView commitAnimations]; } -(void)AnimationDidStop:(id) object { [self.view removeFromSuperview]; } </code></pre> <p>hope the additional info helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload