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

编码 :

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)-|>"
)

有任何想法吗?

阿拉克

最佳答案

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
}

关于ios7 - AutoLayout CGAffineTransform iOS7 iOS8,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26088559/

10-12 18:47