4

我有以下代码来扩展文本区域,每当用户点击该字段并开始编辑时,它就是超级视图:

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    textView.text = @"";

    CGRect titleViewFrame = self.titleLabel.frame;
    titleViewFrame.size.height = kExpandedSubviewFrameHeight;

    CGRect titleTextViewFrame = self.titleTextView.frame;
    titleTextViewFrame.size.height = kExpandedSubviewFrameHeight;

    [UIView animateWithDuration:0.4f
        animations:^{
                         self.titleLabel.frame = titleViewFrame;
                         self.titleTextView.frame = titleTextViewFrame;
        }];
}

一切正常,除了用户第一次点击此字段时,文本视图的 y 原点跳了一点:

在此处输入图像描述

非常感谢任何帮助。

4

1 回答 1

1

有点晚了,但我在调整 uitextview 的大小时遇到​​了同样的问题,并认为它与文本视图的滚动有关。这是我的代码在动画高度时有 0 反弹。我使用 NSLayoutConstraint 来调整我的身高。

- (void)textViewDidChange:(UITextView *)textView
{
    CGSize size = [messageView sizeThatFits:CGSizeMake(messageView.frame.size.width, FLT_MAX)];
    [UIView animateWithDuration:0.4f
                     animations:^{
                         messageHeightConstraint.constant = size.height;
                         [self.view layoutIfNeeded];
                     }
                     completion:^(BOOL finished) {
                         [messageView scrollRangeToVisible:NSMakeRange([messageView.text length], 0)];
                     }
    ];

}
于 2014-01-29T06:31:53.050 回答