티스토리 뷰

example.h 

-(void)keyboardWillShow:(NSNotification *)notice;


example.m

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

if (textfield instance == textField) {

[nameTextField resignFirstResponder];

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

CGRect rect = self.view.frame;

rect.origin.y += 100;

rect.size.height -=100;

self.view.frame = rect;

[UIView commitAnimations];

return YES;

}

}


//view 올리기

-(void)keyboardWillShow:(NSNotification *)notice{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

CGRect rect = self.view.frame;

rect.origin.y = -=100;

rect.size.height += 100; //-100 + 100 = 0 

self.view.frame = rect;

[UIView commitAnimations];


}


-(void)viewWillAppear:(BOOL)animated{

[[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) 

name:UIKeyboardWillShowNotification 

object:self.view.window];



}

-(void)viewWillDisappear:(BOOL)animated{

[[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification 

object:nil];

}


<출처: 프리렉 아이폰 프로그래밍 가이드>