我有一个iOS应用程序通用界面设计使用大小类和自动收费表。在应用程序中,我通过激活和禁用约束来执行基于约束的动画。
下面的方法在“纵向”中有效,但是,我为“横向”大小类安装了可选的约束。在激活/禁用动画约束时如何考虑当前屏幕大小类?
例如,我所拥有的图像--我希望我的动画代码知道它是否应该激活一些约束,而不是其他约束。
-(NSArray*)layoutFullScreen
{
return @[self.imageYCenterConstraint,
self.imageWidthRatioConstraint];
}
-(NSArray*)layoutWorkingScreen
{
return @[self.textLabelCenterYConstraint,
self.imageHeightRatioConstraint];
}
-(void)doAnimation
{
[NSLayoutConstraint deactivateConstraints:[self layoutFullScreen]];
[NSLayoutConstraint activateConstraints:[self layoutWorkingScreen]];
[UIView animateWithDuration:0.6 delay:0 options:0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
发布于 2015-08-05 09:59:53
如果您使用的是size类,则必须考虑的不是旋转,而是UITraitsCollections。您可以在traitCollectionDidChange:
中处理大小类的更改,并相应地修复约束。
https://stackoverflow.com/questions/31839279
复制