【问题标题】:AutoLayout CGAffineTransform iOS7 iOS8自动布局 CGAffineTransform iOS7 iOS8
【发布时间】:2014-11-23 04:14:19
【问题描述】:

几个小时以来,我一直在试图弄清楚为什么当我应用 CGAffineTransformMakeScale 时自动布局在 iOS8 中打破了我的约束,但在 iOS7 中却没有。 (我使用带有 Storyboard 和 Autolayout 的 Xcode 6.0.1 (6A317)。

代码:

TCTGridController *gridController = self.gridController;
stackController.view.frame = gridController.view.frame;
stackController.stackCollectionView.transform = CGAffineTransformMakeScale(0.1, 0.1);

[gridController.view.superview addSubview:stackController.view];

[UIView animateWithDuration:0.2 animations:^{
    stackController.stackCollectionView.transform = CGAffineTransformMakeScale(1, 1);
    [stackController.stackCollectionView layoutIfNeeded];
} completion:^(BOOL finished) {
    [stackController didMoveToParentViewController:self];
}];

iOS7 结果:

iOS8 结果:

iOS8 上的约束错误:

(
"<NSLayoutConstraint:0x7fa126a9b100 V:[_UILayoutGuide:0x7fa126a9a900]-(120)-[TCTCollectionView:0x7fa125139400]>",
"<_UILayoutSupportConstraint:0x7fa126a8b500 V:[_UILayoutGuide:0x7fa126a9a900(0)]>",
"<_UILayoutSupportConstraint:0x7fa126a8a960 V:|-(0)-[_UILayoutGuide:0x7fa126a9a900]   (Names: '|':UIView:0x7fa126a9a810 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa126c86840 h=--- v=--- 'UIView-Encapsulated-Layout-Top' V:[UIView:0x7fa126a9a810]-(0)-|>"
)

有什么想法吗?

阿拉克

【问题讨论】:

    标签: ios7 storyboard ios8 autolayout cgaffinetransform


    【解决方案1】:

    CGAffineTransformIdentity 在 ios7 和 ios8 上的行为不同。这与自动布局和大小类有关。解决办法是去掉与ios7上的动画冲突的约束。

    // solve the constraint-animation problem
    if(NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) {
        // iOS7 remove constraints that conflict with animation
        if (self.centerYAlignment != nil) {
        self.view.removeConstraint(self.centerYAlignment) //is an IBOutlet 
        }
    } else {
        // iOS8 constraint animations are fine
    }
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。 CGAffineTransformMakeScale 在 iOS7 上运行良好,但在 iOS8 上导致“无法同时满足约束”错误。对我来说,解决方案是在应用转换之前将视图添加到父视图并在子视图上调用 layoutIfNeeded。

      之前:

      subview.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
      

      之后:

      [view addSubview:subview];
      [subview layoutIfNeeded];
      subview.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
      

      【讨论】:

      • 非常感谢 - 浪费了我生命中的 2 小时;D [subview layoutIfNeeded]; 完成了这项工作。
      【解决方案3】:

      问题来自于

      stackController.view.frame = gridController.view.frame; 
      

      而不是来自 CGAffineTransformMakeScale。因为我没有取消选中“Resize view from NIB”。 所以要解决这个问题,我取消选中“Resize view from NIB”并添加:

      [stackController.view setTranslatesAutoresizingMaskIntoConstraints:YES];
      

      【讨论】:

        猜你喜欢
        • 2015-02-26
        • 2015-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多