Auto layout can only be used for positioning and resizing. It cannot be used to create the kind of Core Animation transform needed to create a flip transition effect. Thus, the short exact answer is no, there is no way to animate this kind of flip by revitalizing restrictions.
Using the show / hide transition option
However, there is an easy way to change the code that you are already using so that it matches Auto Layout. The way to do this is: (1) add your firstView and secondView to the hierarchy of your view before ordering the animation, (2) to make sure you add auto-layout constraints that define the layout of both of these views and (3) add a parameter to the animation so that you only show / hide two views, instead of tearing down and setting up a new view hierarchy.
In other words, you want something like:
// assert: secondView added to view hierarchy // assert: secondView.hidden == true // assert: secondView has correct constraints [UIView transitionFromView:firstView toView:secondView duration:0.6 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionShowHideTransitionViews completion:nil];
Why is this needed? The reason is that without the UIViewAnimationOptionShowHideTransitionViews option UIViewAnimationOptionShowHideTransitionViews the transitionFromView:toView:duration:options:completion: method will actually manage the view hierarchy and add a new destination view. If automatic layout is enabled, then it will not be selected correctly, since it will not have restrictions.
You can see an example project showing this approach: https://github.com/algal/AutoLayoutFlipDemo
Using view hierarchy manipulation
Alternatively, you can also use your existing transitionFromView:toView:duration:options:completion: call transitionFromView:toView:duration:options:completion: But if you do not just show a representation of a destination that already has restrictions, then you need to use the completion block to add these restrictions, as shown below:
[UIView transitionFromView:firstView toView:secondView duration:0.6 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) { [self.view addConstraint:[NSLayoutConstraint constraintWithItem:secondView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:secondView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]]; }];
A working example of this approach is given here: https://github.com/algal/AutoLayoutFlipDemo2
source share