简体   繁体   中英

iOS project works on iPhone but not in simulator

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 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM