我有一个位于 View 底部的 UITextView。当用户点击它时,我需要将 View 动画化 150px。我正在使用:
- (void)textViewDidBeginEditing:(UITextView *)textView{
和
- (void)textViewDidEndEditing:(UITextView *)textView{
做这个。
在 iOS5 上,它工作正常。但是在 iOS 4.3 上,当 View 是动画时,这个 UITextView 中的内容会向上移动几个像素。
截图:http://cl.ly/1q3e0W2G1M000u1U3w1f
有人遇到过类似的问题吗?
代码:
- (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];
}
最佳答案
在 textViewDidBeginEditing 方法中调用方法时以及动画完成后,您需要重置 TextView 的内容插入...
试试这个代码:
- (void)textViewDidBeginEditing:(UITextView *)textView{
[textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
关于iphone - 动画 View 后 UITextView 错误的内容偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8167538/