I have a very simple scenario that is not working for me. I have one storyboard with two view controllers:
ViewController1
- ViewA
- ViewB
ViewController2
- ViewC
My ViewController1
is working as intended and when I rotate the device the views adjust correctly according to the auto layout that I defined.
My ViewController2
have a Freeform size (768x722) and I unchecked the option "Resize View From Nib".
This is my ViewController1
didLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc2 = [story instantiateViewControllerWithIdentifier:@"vc2"];
[self addChildViewController:vc2];
[vc2 didMoveToParentViewController:self];
[self.viewA addSubview:vc2.view];
}
When I rotate the device the method - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
from ViewControlled2
its called and it shows the correct orientation. However, ViewC
does not resize it self and does not follow my Auto Layout settings.
Anyone know how I can fix? I just want to add my ViewController2
inside ViewA
and keep the Auto Layout working for views of ViewController2
. I need a solution for iOS 7 only, so no compatibility with earlier versions is needed.
Anyone can help me?
I found the solution and I will register it here, just in case someone needs it.
I created an UIViewController property to hold my ViewController2. After that, I added the following method:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
self.vc2.view.frame = self.viewA.bounds;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With