我不确定为什么会这样......
当用户开始在文本字段中输入时,我正在尝试为我的视图设置动画。但该代码仅适用于横向左方向但不适用于横向方向......
这两种方法都被调用......
这是代码..
- (void)keyboardWasShown:(NSNotification *)aNotification {
if ( keyboardShown )
return;
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.size.width += 150;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
keyboardShown = YES;
}
- (void)keyboardWasHidden:(NSNotification *)aNotification {
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.size.width -= 150;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
keyboardShown = NO;
}
截至目前,我刚刚对数值进行了硬编码。
答案 0 :(得分:1)
为什么不动画视图的原点而不是大小?
frame.origin.y -= 150;
和
frame.origin.y = 0;
答案 1 :(得分:0)
好的......在一些帮助下弄清楚......
当您设置视图的框架并将其控制器添加到窗口的根视图控制器时,您应该使用边界....
因为窗框保持不变......
所以这里是新代码的外观......
- (void)keyboardShown:(NSNotification *) aNotification {
if ( keyboardShown )
return;
CGRect frame = self.view.bounds;
frame.origin.y += 150;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:0.3];
self.view.bounds = frame;
[UIView commitAnimations];
keyboardShown = NO;
}
- (void)keyboardHidden:(NSNotification *) aNotification {
CGRect frame = self.view.bounds;
frame.origin.y -= 150;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:0.3];
self.view.bounds = frame;
[UIView commitAnimations];
keyboardShown = NO;
}