Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Orientation Change Detection

Running on iOS 8, I need to change the UI when rotating my app.

Currently I am using this code:

-(BOOL)shouldAutorotate
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation != UIInterfaceOrientationUnknown) [self resetTabBar];

    return YES;
}

What I do it remove the current UI and add a new UI appropriate to the orientation. However, my issue is that this method is called about 4 times every time a single rotation is made.

What is the correct way to make changes upon orientation change in iOS 8?

like image 236
Josh Kahane Avatar asked Oct 11 '14 13:10

Josh Kahane


1 Answers

Timur Kuchkarov is correct, but I'll post the answer since I missed his comment the first time I checked this page.

The iOS 8 method of detecting orientation change (rotation) is implementing the following method of the view controller:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    // Do view manipulation here.
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

Note: The controller's view has not yet transitioned to that size at this time, so be careful if your sizing code relies on the view's current dimensions.

like image 165
Nick Merrill Avatar answered Sep 28 '22 05:09

Nick Merrill