UITextView在animation视图之后的内容偏移量偏移

我有一个UITextView是在视图的底部。 当用户点击它,我需要animation视图150px了。 我在用着:

- (void)textViewDidBeginEditing:(UITextView *)textView{ 

 - (void)textViewDidEndEditing:(UITextView *)textView{ 

做这个。

在iOS5上,它工作正常。 但在iOS 4.3上,当视图被animation时,这个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方法中的调用方法和animation完成后,您需要重置文本视图的内容插入…

试试这个代码:

 - (void)textViewDidBeginEditing:(UITextView *)textView{ [textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; } 

我发现接受的答案造成了一些视觉上的不规范。 以下工作对我来说好多了。

 textView.contentMode = UIViewContentModeTop; 

试试UITextField来解决这个问题。