【问题标题】:iOS how to activate/deactivate layout constraints for a certain size class (orientation)?iOS如何激活/停用某个尺寸类(方向)的布局约束?
【发布时间】:2015-08-05 17:40:13
【问题描述】:

我有一个使用尺寸类和自动布局设计的 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) {
        }];
}

【问题讨论】:

    标签: ios animation autolayout constraints size-classes


    【解决方案1】:

    如果您使用大小类,则不能考虑旋转,而是考虑 UITraitsCollections。您可以处理 traitCollectionDidChange: 中的大小类更改并相应地修复您的约束。

    【讨论】:

      猜你喜欢
      • 2018-04-21
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      相关资源
      最近更新 更多