keypad hides text view - iphone

i am placing a tableview,textview,buttons in a view as like this.
when ever i click on the textview keypad hides textview.To animate up textview i am writing the code as fallows.
- (void) textViewDidBeginEditing:(UITextView *)textView {
[self animateTextField:textView up:YES];
}
- (void) textViewDidEndEditing:(UITextView *)textView {
[self animateTextField:textView up:NO];
}
- (void) animateTextField: (UITextView*) textView up: (BOOL) up {
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
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];
}
But it does n't take any effect.
And To hide the keypad i am writing this code
-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event {
[mytextview resignFirstResponder];
}
it is also does n't take any effect.
can any one please help me.
Thank u in advance.

For resigning keyboard;
Make a ToolBar with bar button and add an IBAction for this and set its y coordinate below the 480(screen hieght)
-(IBAction)hide
{
[mytextview resignFirstResponder];
}
and in viewWillAppear use
myTextView.inputAccessoryView=tlBar;
And add two notification in viewWillAppear for keyboard
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:#selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
and then use these methods for Animation
-(void) keyboardWillShow:(NSNotification *) note
{
if(isAnimate)
[self viewAnimateUpper];
}
-(void)viewAnimateUpper
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
CGRect viewFrame=self.view.frame;
viewFrame.origin.y -=95;//according to you
self.view.frame=viewFrame;
[UIView commitAnimations];
}
-(void)viewAnimatedown
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
CGRect viewFrame=self.view.frame;
viewFrame.origin.y +=95;//according to you
self.view.frame=viewFrame;
[UIView commitAnimations];
}
-(void) keyboardWillHide:(NSNotification *) note
{
if(isAnimate)
{
[self viewAnimatedown];
}
}
Edit:
use textviewShouldBegainEditing
and in this set a boolvariable to yes if your desired textView call this method
isAnimate=YES;

I didn't find a chance to see you view,since my browser says "The image cant be dispalyed,It contains errors."
So try the following options.
Chk whether you have set the delegate of the textField to the files owner.If you have set and still not working,please try the below one.Its like animating the entire view up and down on textedits.
Please make use of the below code.This works for me.What you have to do is double click the .xib file where you want to add text fields.The view along with a window containing file's owner,first responder and a view will also be opened.
Use cmd+shift+l to open the library and add another view.In your .h file add a IBOutlet for the view as IBOutlet UIView *secondview and map to the file's owner.
Now put the text fields whichever has to moved in the second view.Now the default view which will appear when open the .xib file will contain nothing.It will be blank and the controls whichever you have to display will be on the second view.
In the .m file add the second view to the main view as
[self.view addSubview:secondView];
and use this code by customizing the text field names as you wish.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
CGRect viewFrame = self.view.frame;
if(textField==textfield1)
{
[textfield1 resignFirstResponder];
[textfield2 becomeFirstResponder];
}
else if(textField== textfield2)
{
[textfield2 resignFirstResponder];
[textfield3 becomeFirstResponder];
}
else if(textField== textfield3)
{
[textfield3 resignFirstResponder];
[textfield4 becomeFirstResponder];
}
else if(textField== textfield4)
{
[textfield4 resignFirstResponder];
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect viewFrame = secondView.frame;
CGRect textFieldRect =[secondView.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =[secondView.window convertRect:secondView.bounds fromView:secondView];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator =midline - viewRect.origin.y- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[secondView setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CGRect viewFrame = secondView.frame;
viewFrame.origin.y +=animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[secondView setFrame:viewFrame];
[UIView commitAnimations];
}
Let me know does this worked.

Related

How to make a UITextView move up when keyboard is present [duplicate]

This question already has answers here:
How can I make a UITextField move up when the keyboard is present - on starting to edit?
(98 answers)
Closed 9 years ago.
How to move UITextView Up and Down when you start entering some value. Like in TextField we use its delegate method. What to do in case of UITextView ?
While editing complete View will move up and after done editing will move down...
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self animateTextView: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[self animateTextView:NO];
}
- (void) animateTextView:(BOOL) up
{
const int movementDistance =heightKeyboard; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement= movement = (up ? -movementDistance : movementDistance);
NSLog(#"%d",movement);
[UIView beginAnimations: #"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.inputView.frame, 0, movement);
[UIView commitAnimations];
}
I hope this will help you...
Here is a sample code that will handle the keyboard automatically for you. Keyboard avoiding
If you are using TableView then your tableView must be a subclass of TPKeyboardAvoidingTableView and if you are using scrollview then your scrollview must be a subclass of TPKeyboardAvoidingScrollView. And this library will automatically do keyboard handling for you.
I suggest you to take a look at this guide
in particular at section: Moving Content That Is Located Under the Keyboard.
I have used this approach successfully several times.
I did by changing the frame.
-(void)textViewDidBeginEditing:(UITextView *)textView{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:viewMsg cache:YES];
viewMsg.frame = CGRectMake(10, 50, 300, 200);
[UIView commitAnimations];
NSLog(#"Started editing target!");
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:viewMsg cache:YES];
viewMsg.frame = CGRectMake(10, 150, 300, 200);
[UIView commitAnimations];
}
#define kOFFSET_FOR_KEYBOARD 80.0
-(void)keyboardWillShow {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:mailTf])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
CGRect rect = self.view.frame;
if (movedUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
- (void)viewWillAppear:(BOOL)animated
{
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
try This CODE.....

iPad Keyboard Covers UITextField in table view

I have a problem
i have a 15 text fields in a table view.when i am entering text to last text field it is covering by key board.Any one please give me a solution for this.
My textfields are in a detail view controleer of split view in IPAD,
Thanks in advance for your solution
You can add these lines of coding:
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
CGRect rect = self.view.frame;
if (movedUp)
{
NSLog(#"MOVE-UP");
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
// rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
NSLog(#"MOVE-DOWN");
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
// rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
-(void)keyboardWillShow
{
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide
{
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
And in viewDidAppear:
-(void)viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
you have to define this also #define kOFFSET_FOR_KEYBOARD 100.0//as you want
//call when textfield editing started
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[self animateTextField: indexPath up: YES];
}
//Text Field after editing ended
(void)textFieldDidEndEditing:(UITextField *)textField{
[self animateTextField: indexPath up: NO];
}
//code for animateTextField .The movement Distance will change as per requirement
(void) animateTextField: (NSIndexPath*) indexPath up: (BOOL) up{
const int movementDistance =indexPath.section==0?20: 180;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
NSLog(#"movement:%d",movement);
[UIView beginAnimations: #"aimation" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame= CGRectOffset(self.view.frame,0, movement);
[UIView commitAnimations];
}

how can i scroll between many textfield and textarea on uiscrollview?

i have an nsarray of textfields and another of textarea. I have also a toolbar with next and previous button to manage navigation between my fields. I made a fonction in textfieldDidBeginEditing and another in textfieldDidEndEditing but it didn't work correctly.
my function is :
if (textField.frame.origin.y > 180) {
[UIScrollView beginAnimations:nil context:NULL];
[UIScrollView setAnimationDelegate:self];
[UIScrollView setAnimationDuration:0.4];
[UIScrollView setAnimationBeginsFromCurrentState:YES];
CGFloat updatedY = 150;
self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x,self.scrollView.frame.origin.y - updatedY, self.scrollView.frame.size.width,
self.scrollView.frame.size.height);
[UIScrollView commitAnimations];
}
Any help will be appreciated.
I think you want Keyboard handler. The one I am using is a very good keyboard handler.
Keyboard Handler by Sukhpal Singh
This is a very good tutorial from one of my good friend and You can use this.
For using this you just have to write a single line of code.
AutoScroller * scroller=[AutoScroller addAutoScrollTo:self.scrollView isDoneToolBarNeeded:NO];
yes its done.
Please try to use this one
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:.30];
[self scrollViewToCenterOfScreen:textView];
[UIView commitAnimations];
return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:.30];
[self scrollViewToCenterOfScreen:textField];
[UIView commitAnimations];
return YES;
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView
{
CGFloat y ;
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat avaliableHeight = applicationFrame.size.height - 250;
y = viewCenterY - avaliableHeight / 2.0f;
if (y < 0)
{
y = 0;
}
[scrollView setContentOffset:CGPointMake(0, y)];
}
try this code:
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
[clientscrollview setContentOffset:CGPointMake(0, textField.center.y-180) animated:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[clientscrollview setContentOffset:CGPointMake(0, 0) animated:YES];
[textField resignFirstResponder];
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[clientscrollview setContentOffset:CGPointMake(0,textView.center.y-180) animated:YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[clientscrollview resignFirstResponder];
[clientscrollview setContentOffset:CGPointMake(0,0) animated:YES];
}

Back ground resizing on keyboard visiblity

I'm using scroll view in my application ,since when i click on dob text-field the datepicker view is showing as a pop up ,on further when i click in continuous text field the view is being like in the image,Here my code,
For date picker visibility.
UIDatePicker pop up after UIButton is pressed
For keyboard orientation
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[dob resignFirstResponder];
if (txt1.textColor == [UIColor lightGrayColor]) {
txt1.text = #"";
txt1.textColor = [UIColor blackColor];
}
if ([textField isEqual:dob])
{
[self but];
[dob resignFirstResponder];
//return NO;
}
//[self animateTextField:textField up:YES];
[textField setClearButtonMode:UITextFieldViewModeWhileEditing];
CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.1 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//[self animateTextField:textField up:NO];
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
return [textField resignFirstResponder];
return [txt1 resignFirstResponder];
}
Can any one help me to clear.
You need to resize your scrollview when the key board appears.
this can be done by adding:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:#selector(keyboardShown) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:#selector(keyboardHidden) name:UIKeyboardWillHideNotification object:nil];
in the viewDidLoad.
Then define the methods keyboardShown and keyboardHidden in your implementation file.
These methods will be called automatically when keyboard appears and disappears.
In these methods resize your background view accordingly. since you are using scroll view please mind the scrollView's contectView size also. as its different from the view's frame size.
For the basic problem of having a scroll view and needing to move its contents when the keyboard appears, I have found this open source scroll view class by Michael Tyson to be very useful.
Basically, you just add the TPKeyboardAvoidingScrollView class to your project, and use it where you would normally use a UIScrollView. The child views that you add to the TPKeyboardAvoidingScrollView can be UITextField objects, if you like. When you tap those fields to begin editing, and the keyboard appears, the TPKeyboardAvoidingScrollView container will choose an appropriate scroll position so that the field that's being edited is not hidden by the keyboard, and you won't see black bars like you have in your screen shot.
I think i get the problem.
jst for example, in ur register page, many textfields and button for DOB.
So, basically when any textfield editing and after that instead of return keyboard, user press button of DOB.
so u have to first resignFirstRespoder ur all textfields.
Problem is when u startEditing frame set to top and endEditing set to bottom but when u click to button endEditing not called so frame not set to bottom. And again u startEditing frame again set to top so problem aries.
I hope this help...

Scroll view when editing not working correctly

I am trying to make a UIScrollView scroll when the user starts editing a UITextField and the text field is hidden by the keyboard. I am using an example from the following thread.
How to make a UITextField move up when keyboard is present
I have four UITextFields in my view. When the keyboard is shown for the first time the view does not scroll automatically. If I click another text field with the keyboard shown, the UIScrollView scrolls as intended.
Hiding the keyboard (by tapping the "Done" button) and tapping a UITextField again the same issue occurs: the UIScrollView does not scroll at first but when changing focus to another text field it scrolls perfectly.
Can anyone please help me?
In viewDidLoad I set the size of the scrollView
keyboardIsShown = NO;
CGSize scrollContentSize = CGSizeMake(320, 350);
self.scrollView.contentSize = scrollContentSize;
I register for the keyboard notifications in viewWillAppear
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:self.view.window];
Then I unregister in viewWillDisappear
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
The following two methods are called by the notifications.
- (void)keyboardWillShow:(NSNotification *)n {
if (keyboardIsShown) {
return;
}
NSDictionary *userInfo = [n userInfo];
NSValue *boundsValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [boundsValue CGRectValue].size;
CGRect viewFrame = self.scrollView.frame;
viewFrame.size.height -= (keyboardSize.height - 50);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[self.scrollView setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = YES;
}
- (void)keyboardWillHide:(NSNotification *)n {
NSDictionary *userInfo = [n userInfo];
NSValue *boundsValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [boundsValue CGRectValue].size;
CGRect viewFrame = self.scrollView.frame;
viewFrame.size.height += (keyboardSize.height - 50);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[self.scrollView setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = NO;
}
If you want to show the textfeild when keyboard is visible then use the code below. Don't go with the scrollview. If it is compulsory to use a scrollView then neglect this answer.
#define kOFFSET_FOR_KEYBOARD 280.0
- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMoveUp:NO];
}
- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMoveUp:YES];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
stayup = YES;
[self setViewMoveUp:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
stayup = NO;
[self setViewMoveUp:NO];
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMoveUp:(BOOL)moveUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect rect = self.view.frame;
if (moveUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
if (rect.origin.y == 0 ) {
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
//rect.size.height += kOFFSET_FOR_KEYBOARD;
}
}
else
{
if (stayup == NO) {
rect.origin.y += kOFFSET_FOR_KEYBOARD;
//rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
}
self.view.frame = rect;
[UIView commitAnimations];
}
Try this methods. Edit it according to your requirement.