动画视图后UITextView错误内容偏移 [英] UITextView bad content offset after animating view

查看:121
本文介绍了动画视图后UITextView错误内容偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位于视图底部的UITextView。当用户点击它时,我需要将视图设置为150px。我正在使用:

I have one UITextView which is on the bottom of view. When user tap in it, I need to animate view 150px up. I'm using:

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

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

进行此操作。

在iOS5上,它运行正常。但是在iOS 4.3上,当视图被设置动画时,此UITextView中的内容会向上几个像素。

On iOS5, it works fine. But on iOS 4.3, when view is animated, content in this UITextView goes few pixels up.

屏幕截图: 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方法中调用方法时以及完成动画后的文本视图...

You need reset content inset of your text view when call method in textViewDidBeginEditing method and after you animation is done...

试用此代码:

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

这篇关于动画视图后UITextView错误内容偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆