当键盘显示时,我的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