如何在iOS 6.0中使用以下方法支持界面方向:
shouldAutorotate supportedInterfaceOrientations preferredInterfaceOrientationForPresentation
因为“shouldAutorotatetoInterfaceOrientation”在iOS 6.0中已弃用。
谢谢。
解决方法
iOS 5中已弃用的方法:
// Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
在iOS 6中替换,以及相当于上述弃用的iOS 5方法:
- (BOOL) shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; }
希望这可以帮助。
[编辑#1:添加我的UIViewController成功地开始在肖像模式在XCode 4.5在iPhone 6.0模拟器]
#import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (id)initWithNibName:(Nsstring *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; }
[#edit 2:仅支持iOS 5和iOS 6的仅风景应用程序的示例代码]
- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; }