當鍵盤顯示時,我的UIView沒有向上移動,並且在隱藏鍵盤時也沒有移動。當鍵盤顯示時UIView不向上移動AutoLayout
這種編碼是在viewDidLoad中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
這個編碼是休息。
- (void)keyboardDidShow:(NSNotification *)note
{
[self animateTextField:TRUE];
}
- (void)keyboardDidHide:(NSNotification *)note
{
[self animateTextField:FALSE];
}
-(void)animateTextField :(BOOL)up
{
const int movementDistance = -130; // tweak as needed
const float movementDuration = 1.0; // tweak as needed
int movement = (up ? movementDistance : - movementDistance);
[UIView beginAnimations: @"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
_buttonsView.frame = CGRectOffset(_buttonsView.frame, 0, movement);
[UIView commitAnimations];
}
是你嗎使用自動佈局?如果自動佈局爲ON,則不能直接更改幀或中心 – 0yeoj
@ 0yeoj yap,那麼我使用自動佈局,因此有任何解決方法,請問? – ppshein
@ 0yeoj能發表完整答案嗎? – ppshein