IOS开发2-ipad 隐藏键盘动画,可用来实现去除挡住view的操作

// Call this method somewhere in your view controller setup code.

- (void)viewDidLoad

{

    [self registerForKeyboardNotifications];


    [super viewDidLoad];

}

- (void)registerForKeyboardNotifications

{
//先取消之前的观察者
 [[NSNotificationCenter defaultCenter] removeObserver:self 

 name:UIKeyboardDidShowNotification 

   object:nil];

 [[NSNotificationCenter defaultCenter] removeObserver:self 

 name:UIKeyboardDidHideNotification 

   object:nil];

 

    [[NSNotificationCenter defaultCenter] addObserver:self

  selector:@selector(keyboardWasShown:)

  name:UIKeyboardDidShowNotification object:nil];

 
//注册观察者
    [[NSNotificationCenter defaultCenter] addObserver:self

  selector:@selector(keyboardWasHidden:)

  name:UIKeyboardDidHideNotification object:nil];

}

 

// Called when the UIKeyboardDidShowNotification is sent.

- (void)keyboardWasShown:(NSNotification*)aNotification

{

 

 //self.frame = CGRectMake(0, -90, 320, 480);

}

 

// Called when the UIKeyboardDidHideNotification is sent 点下ipad的隐藏键盘键触发

- (void)keyboardWasHidden:(NSNotification*)aNotification

{

 

[userField resignFirstResponder];  //必须的

    [passwordTxt resignFirstResponder];

    [UIView beginAnimations:@"LoginViewController" context:nil];

    [UIView setAnimationDuration:0.5];

    self.view.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);

    [UIView commitAnimations];    

 

}


你可能感兴趣的:(IOS开发2-ipad 隐藏键盘动画,可用来实现去除挡住view的操作)