Make a slide show to make room for the keyboard?

I just started learning how to program iPhone apps, and I can't figure out how to take a picture of the slide when the keyboard appears (so you can still see the text box that you enter). How it's done?

+4
source share
5 answers

If this is okay visually, the easiest way is to move the entire self.view.frame file and then move it back when you're done.

static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3f; - (void) animateForToNewYPosition:(int)newYPosition { // move for kdb if (self.view.frame.origin.y == newYPosition) { return; } // start animation CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; // move it self.view.frame.origin.y = newYPosition; [UIView commitAnimations]; } 
+2
source

One way to do this is to contain everything in a UIScrollView, and then scroll up the content. Another way is to move the view yourself, usually with Core Animation, to make it look good.

A good place to start is with the documentation. There's even a section referenced by β€œMoving Content Under the Keyboard” that will point you in the right direction.

+1
source

Suppose you need to move the view to a text field whose tag is 4 (if you have more than 1 txt field and one of them is closed by the keyboard), use the textField delegation method

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { if(textField.tag==4) CGRect viewFrame; viewFrame=self.view.frame; if(viewFrame.origin.y==-100) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; viewFrame.origin.y+=100; self.view.frame=viewFrame; [UIView commitAnimations]; } } 

it moves your presentation. now to move down you need the code in the textField anothe delegate method

 - (BOOL)textFieldShouldReturn:(UITextField *)textField { if(textField.tag==4) { CGRect viewFrame; viewFrame=self.view.frame; if(viewFrame.origin.y==-100) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; viewFrame.origin.y+=100; self.view.frame=viewFrame; [UIView commitAnimations]; } } } 

In the case of text viewing, you need to click a button, and to move up you need this delegate

 - (BOOL)textViewShouldBeginEditing:(UITextView *)textView 

and use the same code as textField

And moving down, you need a button on the navigation bar or add a toolbar and set this toolbar above the keyboard using the same animation. For the button, you need the same code to move down that is applicable to textField.

Hope this helps you.

0
source
  http://objectivecwithsuraj.blogspot.in/2012/06/making-view-slide-up-to-make-room-for.html Add a UIScrollview - scrollview to your UIView and set delegates for UITextFields & UIScrollview - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == txtFieldName) { [txtFieldCellNo becomeFirstResponder]; } else if (textField == txtFieldCellNo) { [txtFieldEmail becomeFirstResponder]; } else { [textField resignFirstResponder]; } return YES; } - (void)textFieldDidBeginEditing:(UITextField *)textField { [self animateTextField:txtFieldName up:YES]; } - (void)textFieldDidEndEditing:(UITextField *)textField { [self animateTextField:txtFieldEmail up:NO]; } - (void) animateTextField: (UITextField*) textField up: (BOOL) up { const int movementDistance = 80; const float movementDuration = 0.3f; int movement = (up ? -movementDistance : movementDistance); [UIView beginAnimations: @"anim" context: nil]; [UIView setAnimationBeginsFromCurrentState: YES]; [UIView setAnimationDuration: movementDuration]; self.view.frame = CGRectOffset(self.view.frame,0, movement); [UIView commitAnimations]; 

}

0
source

I found that using keyboard notifications improved for my application than using the UITextField delegate protocol for textFieldDidBeginEditing and textFieldDidEndEditing. Notifications are the keyboard WillShow and keyboardWillHide. You can check for a UITextField or UITextView that requires the view to move with these notifications and then conditionally move the view. The advantage of my application is that I have a lot of UITextTields, and notifications make it easier to save the view above the keyboard when editing moves from one field to another.

0
source

All Articles