Search code examples
ios7storyboardios8autolayoutcgaffinetransform

AutoLayout CGAffineTransform iOS7 iOS8


For hours I've been trying to figure why autolayout is breaking my constraint in iOS8 but not in iOS7 when I apply CGAffineTransformMakeScale. (I use Xcode 6.0.1 (6A317) with Storyboard and Autolayout).

The code :

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

Constraint 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?

Alak


Solution

  • CGAffineTransformIdentity behaves differently on ios7 and ios8. This has to do with auto-layout and size classes. The solution is to remove constraints that conflict with the 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
    }