2014-09-28 54 views
3

几个小时我一直在试图弄清楚为什么autolayout在iOS8中突破我的约束,而在我应用CGAffineTransformMakeScale时却没有在iOS7中实现。 (我使用Xcode 6.0.1(6A317)与Storyboard和Autolayout)。AutoLayout CGAffineTransform iOS7 iOS8

的代码:

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结果:

enter image description here

iOS8上结果:

enter image description here

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

任何想法?

奥洛克

回答

7

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 
} 
1

问题来自

stackController.view.frame = gridController.view.frame; 
从CGAffineTransformMakeScale

不能及的。因为我没有取消选中“调整来自NIB的视图”。 因此,要解决这个问题我取消选中“调整从NIB视图”,并添加:

[stackController.view setTranslatesAutoresizingMaskIntoConstraints:YES]; 
2

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

前:

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

后:

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

非常感谢你 - 我生命的浪费小时; d'[子视图layoutIfNeeded]'做的工作。 – mklb 2015-04-11 22:05:50

相关问题