AutoLayout CGAffineTransform iOS7 iOS8

For several hours I have been trying to figure out why autoplay violates my limitation in iOS8 but not iOS7 when I apply CGAffineTransformMakeScale. (I am using Xcode 6.0.1 (6A317) with Storyboard and 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 result:

enter image description here

IOS8 result:

enter image description here

Limit error on 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)-|>"


Any ideas?



source to share

3 answers

CGAffineTransformIdentity behaves differently on ios7 and ios8. It has to do with the auto layout and sizing classes. The solution is to remove the restrictions that conflict with animation on 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




I had the same problem. CGAffineTransformMakeScale worked fine on iOS7, but threw an "Unable to satisfy constraints at the same time" error on iOS8. The solution for me was to add the view to the parent and call layoutIfNeeded on the subview before applying the transform.


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



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




The problem arises from

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


not from CGAffineTransformMakeScale. Because I haven't unchecked the Resize with NIB checkbox. So to fix this, uncheck "Resize from NIB" and add:

[stackController.view setTranslatesAutoresizingMaskIntoConstraints:YES];




All Articles