我有以下代码来扩展文本区域&只要用户点击该字段,它就是超级视图。编辑开始:
- (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原点跳起来:
非常感谢任何帮助。
答案 0 :(得分: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)];
}
];
}