Reputation: 313
I've got an app that I used Storyboard and autolayout to lay out. I used a UINavigationViewController to programmatically transition between UIViewControllers on button pushes. I used XCode 6 with a minimum iOS version number of 7.1 (tested on iPhone 4s).
I wanted to write a universal interface that would scale to all screen sizes (iPhone, iPad, etc.). In order to do this, I used UIViews that were defined proportionally to screen size to separate the views (please see Figure 1):
Figure 1 - Screenshot of main page of test application
In figure 1 as shown above, the red squares are UIViews that are defined proportionally to screen size that are used to "space out" the "real" views (those that are blue and gray).
Unfortunately, I began to notice that when the user transitioned between UIViewControllers, the views in the view controllers would "resize" (views would move a few pixels or resize by a few pixels) just after transition. This creates the rather irritating experience of the entire interface changing slightly after the user transitions to the appropriate screen.
I culled the project down to a reasonable minimum of code required to produce this resizing effect in hopes that someone could help me out (because I'm at a loss).
Storyboard view hierarchy for 1st view controller:
Constraints for first view controller:
Setup of second view controller:
Code used to transition from 1st to second controller (push):
- (IBAction)transitionForward:(UIButton *)sender
{
UIViewController *controller = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"BackController"];
[self.navigationController pushViewController:controller animated:YES];
}
Code used to pop from second controller to the first one:
- (IBAction)transitionBack:(UIButton *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
As stated, the issue is that the interface appears to slightly resize itself/move around right after the view controller loads after a push/pop triggered by the user clicking on a button. This effect is rather jarring and I would really appreciate any suggestions on how to stop it.
The simplified project that demonstrates the issue can be found at Github.
If there is anything else I can provide, please just ask. Thank you for your time and assistance.
Edit: Upon further investigation, it appears that the viewDidLayoutSubviews method of the view controllers is being called twice on view controller transition (in case that helps anyone diagnose the problem).
Upvotes: 0
Views: 119
Reputation: 562
Try replacing your push and pop function with this code and leme know your requirements are meet or not.
- (IBAction)transitionBack:(UIButton *)sender
{
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionFromLeft;
[transition setType:kCATransitionPush];
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
}
- (IBAction)transitionForward:(UIButton *)sender
{
UIViewController *controller = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"BackController"];
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionFromRight;
[transition setType:kCATransitionPush];
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:controller animated:NO];
}
Upvotes: 1