iOS 项目可以在 iPhone 上运行,但不能在模拟器中运行

iOS project works on iPhone but not in simulator

你好,

我的 iOS 项目在我的 iPhone 4s 7.1.2 上完美支持景观和 运行,但在模拟器中不支持。

这里是一些截图:

iPhone Landscape

Simulator Landscape

两个屏幕截图都是在横向模式下截取的,模拟器似乎没有正确调整板的大小

这是我用来改变方向的代码。

- (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)];
    }];
}

}

感谢您的帮助:)

我没有尝试过您的代码,但我坚信您所看到的是由 弃用的 API 引起的。 Official documentation here gives details, and the new API that does what you want is viewWillTransitionToSize:withTransitionCoordinator:

在Whosebug上还有一些其他的问题,比如这样谈论解决方案:willAnimateRotationToInterfaceOrientation not called on ios6/7