【发布时间】:2014-05-26 13:26:23
【问题描述】:
我正在学习教程中的动画自动布局
http://weblog.invasivecode.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was
一切都很完美。
当我尝试在我的应用程序中使用此概念时,尝试从下到上为设置屏幕(UIView)设置动画,当设置屏幕只是一个空的 UIView 时,它非常有用,
但如果我将 UILabel 作为子视图添加到此设置屏幕,动画就会消失。 从设置屏幕中删除此 UILabel 后,动画可见。
这是我连接的插座
__weak IBOutlet UIView *settingsView;
__weak IBOutlet NSLayoutConstraint *settingsBottomConstraint;
__weak IBOutlet NSLayoutConstraint *settingsViewHeightConstraint;
View 确实加载了设置方法(setupViews)
-(void)setupViews
{
settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
[settingsView setNeedsUpdateConstraints];
[settingsView layoutIfNeeded];
isSettingsHidden = YES;
}
隐藏/取消隐藏方法
- (IBAction)showSettingsScreen:(id)sender {
if (isSettingsHidden) {
settingsBottomConstraint.constant = 0;
[settingsView setNeedsUpdateConstraints];
[UIView animateWithDuration:.3 animations:^{
[settingsView layoutIfNeeded];
}];
}
else{
settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
[settingsView setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3 animations:^{
[settingsView layoutIfNeeded];
}];
}
isSettingsHidden = !isSettingsHidden;
}
我的问题似乎类似于 Issue with UIView Auto Layout Animation
【问题讨论】:
-
你的 UILabel 有什么限制?
-
@Iftekhar,我已经尝试了这两个选项。 1. 只需将标签放到 UIView(即没有约束)和 2. 将宽度、高度、顶部空间的约束添加到 superview 并导致 superview。没有工作。
标签: ios ios7 autolayout uiviewanimation ios10