0

Bonjour,

My iOS project support landscape and run perfectly on my iPhone 4s 7.1.2 but not in the simulator.

Here some screenshot :

iPhone Landscape

Simulator Landscape

Both screenshots have been taken in landscape mode and the simulator does not seem to resize the board correctly

Here the code I use to change orientation.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
    [UIView animateWithDuration:duration animations:^{

        [[UIApplication sharedApplication] setStatusBarHidden:YES];

        int width = [[UIScreen mainScreen] bounds].size.width - [[UIApplication sharedApplication] statusBarFrame].size.width - 10;
        int height = width;

        int x = 5;
        int y = ([[UIScreen mainScreen] bounds].size.width / 2) - (width / 2);

        [board setFrame:CGRectMake(x, y, width, height)];
    }];
}
else {
    [UIView animateWithDuration:duration animations:^{

        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [board setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.width)];
    }];
}

}

Thanks for your help :)

  • Have you set breakpoints to see what values you're getting? – AdamPro13 Jan 16 '15 at 23:29
  • As far as I know, willAnimateRotationToInterfaceOrientation is not working on simulator, because it's triggered by the acceleration sensor of the iPhone device. Obviously, the simulator doesn't have one. – ljk321 Jan 17 '15 at 00:10
  • You can on the iOS Simulator -> Hardware -> Rotate Left / Rotate Right – user3650409 Jan 17 '15 at 00:27

1 Answers1

0

I haven't tried your code but I strongly believe what you see is caused by the deprecated API. Official documentation here gives details, and the new API that does what you want is viewWillTransitionToSize:withTransitionCoordinator:

Also there are some other questions on stackoverflow like this talking about solutions: willAnimateRotationToInterfaceOrientation not called on ios6/7

Community
  • 1
  • 1
kcome
  • 1,166
  • 9
  • 22
  • You are right, willAnimateRotationToInterfaceOrientation:duration: is deprecated in iOS 8... I tried viewWillTransitionToSize:withTransitionCoordinator: it seem to works fine on the simulator. Thanks a lot – user3650409 Jan 17 '15 at 00:36
  • Glad to help. Also, thanks for giving me an "Answer" mark and 1UP :) – kcome Jan 17 '15 at 00:47