在需要同时在iOS 5.1和iOS 6.0上运行的通用应用程序中,我使用上面的代码来允许在两个版本中进行旋转,并且都在 iPhone 上和 iPad 上。有没有更好的方法来做到这一点,同时保持两个版本之间的兼容性并且不使用已弃用的功能?使用上面的代码,我在 iOS 6.0 的 iPad 上遇到了一些小问题,有时......
谢谢你。
// Override to allow orientations other than the default portrait orientation.
// Rotation for v. 5.1.1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// on iPad support all orientations
return YES;
}
else {
// on iPhone/iPod support all orientations except Portrait Upside Down
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
return NO;
}
// Rotation 6.0
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
// Tell the system what we support
-(NSUInteger)supportedInterfaceOrientations
{
// return UIInterfaceOrientationMaskLandscapeRight;
// return UIInterfaceOrientationMaskAll;
return UIInterfaceOrientationMaskAllButUpsideDown;
}
添加:经过一些测试后,我在模拟器中再次遇到了错误:slitViewController 的左侧部分变黑(不总是)并出现上述错误(然后再次运行,旋转 iPad):
<Error>: CGImageCreate: invalid image size: 0 x 0.
<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
<Error>: CGContextGetCompositeOperation: invalid context 0x0
<Error>: CGContextSetCompositeOperation: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
...