ios - UIView动画中初始调整UITextView帧大小时跳转

标签 ios objective-c uitextview uiviewanimation

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

- (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;
        }];
}

一切正常,除了用户第一次点击此字段时, TextView 的 y 原点向上跳了一点:

enter image description here

非常感谢任何帮助。

最佳答案

有点晚了,但我在调整 uitextview 大小时遇到​​了同样的问题,我认为它与 TextView 的滚动有关。这是我的代码,在设置高度动画时反弹为 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)];
                     }
    ];

}

关于ios - UIView动画中初始调整UITextView帧大小时跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18219597/

相关文章:

ios - 以编程方式更改单元格中 ImageView 的约束

ios - 一些 UI 控件在模拟应用程序时位于屏幕外

iphone - 如何在 Objective-C 中定义和使用 ENUM?

Swift UITextView LayoutManager 子类

iphone - 防止 sqlite 转义反斜杠

ios - 如何在 UIWebView 而不是 Safari 中打开 UITextView 网络链接?

ios - 核心数据 - 预填充数据时模型不兼容

iphone - 应用程序在我的设备上崩溃,但在模拟器中以及通过 xcode 调试时运行良好

具有弱 self 的 Objective-C 宏

ios - Error Domain=NSCocoaErrorDomain Code=3840 是属于服务器端还是本地代码端?