我正在使用 iOS6 设备 xcode 4.5 和山狮 mac。在我的应用程序中,我以纵向模式(3 个屏幕)开始。但是第 4 个屏幕应该是横向的,并且应该支持横向左侧和横向右侧。
大多数解释都显示了如何旋转。
在 appddelegate 中使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navigationController.navigationBar.tintColor = [UIColor blackColor];
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[self.window addSubview: navigationController.view];
}
else
{
// use this mehod on ios6
[self.window setRootViewController:navigationController];
}
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.shouldRotate ) //shouldRotate is my flag
{
self.shouldRotate = NO;
return (UIInterfaceOrientationMaskLandscapeRight);
}
return (UIInterfaceOrientationMaskPortrait);
}
在我的视图控制器中,它应该是横向的并且正在使用
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
appDelegate.shouldRotate = YES;
// Custom initialization
}
return self;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
在我的视图控制器中,它们是 potrait 正在正常工作,正在使用
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
有人可以建议这样做吗
提前致谢