我有一个 UITextView 位于视图底部。当用户点击它时,我需要将视图动画放大 150 像素。我在用着:
- (void)textViewDidBeginEditing:(UITextView *)textView{
and
- (void)textViewDidEndEditing:(UITextView *)textView{
来做这个。
在iOS5上,它运行良好。但在 iOS 4.3 上,当视图动画化时,此 UITextView 中的内容会向上移动几个像素。
截屏:http://cl.ly/1q3e0W2G1M000u1U3w1f http://cl.ly/1q3e0W2G1M000u1U3w1f
有人遇到类似问题吗?
Code:
- (void)textViewDidBeginEditing:(UITextView *)textView{
if([textView.text isEqualToString:@"Placeholder text"]){
textView.text = @"";
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 150.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
if([textView.text isEqualToString:@""]){
textView.text = @"Placeholder text";
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 150.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
当 textView 中的调用方法开始编辑方法以及动画完成后,您需要重置文本视图的内容插入...
试试这个代码:
- (void)textViewDidBeginEditing:(UITextView *)textView{
[textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)