Gri*_*cha 2 objective-c autolayout ios6
我有几个UITextView.每个TextView都会在焦点上改变它的大小 - 它增长大约50px,动画如下:
[UITextView animateWithDuration:.1f animations:^{
CGRect new_frame = textView.frame;
new_frame.size.height += height;
textView.frame = new_frame;
}];
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我需要在聚焦的50px下移动TextViews(显然还有动画).我想知道如何以最简单的方式做到这一点.我的应用只是iOS6,所以我可以使用自动布局.我尝试过但失败了.我试过使用支柱和弹簧 - 也失败了.
想到的唯一解决方案就是用动画移动50 px的每个元素.但这对我来说听起来很便宜.有什么想法怎么做?是否可以使用自动布局?
编辑
以下是我一直在尝试的布局:


单击第一个TextView后,它在模拟器中的外观如下:

因此,您可以看到它覆盖下一个视图并且不保留约束.
不要将帧与自动布局相结合,这会给你带来不可预测的结果.
从第二个顶部删除约束UITextView到超级视图的顶部.
然后为该高度约束创建一个出口UITextView.
使用以下代码调整高度UITextView:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[UITextView animateWithDuration:.1f animations:^{
self.textViewHeightConstraint.constant +=50;
[self.view layoutIfNeeded];
}];
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
[UITextView animateWithDuration:.1f animations:^{
self.textViewHeightConstraint.constant -=50;
[self.view layoutIfNeeded];
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
875 次 |
| 最近记录: |