gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:10:17 24 4
gpt4 key购买 nike

我有以下代码来扩展文本区域,每当用户点击该字段并开始编辑时,它就是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com