2014-09-25 90 views

回答

1

經過一段時間我發現UIKeyboardNotification有一個可以處理這個問題的通知。此通知是UIKeyboardDidChangeFrameNotification

小的代碼示例:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; 

接收通知:

- (void)keyboardWillChangeFrame:(NSNotification *)notification 
{ 
    [self.view layoutIfNeeded]; 
    [UIView animateWithDuration:0.2 
        animations:^{ 
         [self.bottomConstrein setConstant:50]; 
         [self.view layoutIfNeeded]; 
        }]; 
}