iphone - 动画 View 后 UITextView 错误的内容偏移量

标签 iphone ios ios4 ios5 uitextview

我有一个位于 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/

相关文章:

ios - 大型 UIImageView 的动画变换时性能不佳

iPhone UIDatePicker 蓝色突出显示不会在新的选择器行上更新

iphone - 如何将需要 iOS4 的静态库添加到部署目标设置为 3.0 的项目中?

iphone - 将自定义表情符号复制到剪贴板

iphone - iPhone 静态库中的核心数据

iPhone 摄像头亮度...它是如何物理测量的?

ios - 在文件系统中创建一个随机文件夹并保存下载的文件iOS

iphone - ASIHttpRequest 的编码问题

iphone - 对核心数据对象进行分组

iphone - 如何使这个应用程序屏幕滚动?