我的主視圖底部有一個按鈕,我想在鍵盤顯示時使用鍵盤進行動畫處理。使用鍵盤顯示的動畫效果(按鈕)
我的按鈕設置像這樣在我的故事板的限制:
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myConstraint;
添加時鍵盤顯示通知:
我已經在代碼鏈接的約束:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
這裏是keyboardWillShow
實現:
- (void)keyboardWillShow: (NSNotification *)notification {
NSDictionary *dictionary = notification.userInfo;
CGRect keyboardFrame = [dictionary[UIKeyboardFrameEndUserInfoKey] CGRectValue];
[UIView animateWithDuration:1.0f animations:^{
self.myConstraint.constant = keyboardFrame.size.height + 18;
}];
}
雖然它的工作原理,按鈕不會動畫,而是立即設置在視圖上新的位置。我試圖添加一個完成塊來查看會發生什麼,實際上完成是立即調用,而不是等待一秒鐘,因爲它應該...
什麼是錯?謝謝你的幫助。
明白了!謝謝。 – Someday