当键盘出现在文本字段上时,我有以下代码用于上下移动视图.
-(void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"height before animation%f",self.view.frame.size.height);
NSLog(@"%f",self.view.frame.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0,-216,320,460)];
[UIView commitAnimations];
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0,0,320,460)];
[UIView commitAnimations];
NSLog(@"height after animation %f",self.view.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
这是我在键盘出现然后编辑完成时得到的示例日志:
2014-01-21 11:00:51.194 Master-view[456:70b] height before animation 568.000000
2014-01-21 11:00:53.635 Master-view[456:70b] height after animation 460.000000
Run Code Online (Sandbox Code Playgroud)
视图的高度似乎降低了,这使得屏幕的底部不可互动.为什么会这样?
视图正在向上移动,也没有问题.在视觉上似乎没有区别.在升空之前存在的所有元素都在下降后存在.但是屏幕底部的元素(超过460.0的高度)并不难解决.
-(void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"height before animation%f",self.view.frame.size.height);
NSLog(@"%f",self.view.frame.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0,-216,320,self.view.frame.size.height)];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0,0,320,self.view.frame.size.height)];
[UIView commitAnimations];
NSLog(@"height after animation %f",self.view.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
我根据视图高度设置框架,你只需要在关键开始时改变y位置,并在结束编辑时尝试将其设置回来可能对你有所帮助
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |