iOS6中的横向模式在应用程序的中间

时间:2012-12-06 13:32:05

标签: iphone ios

使用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;
}

在我的viewcontrollers中,potrait正在使用

正常工作
- (BOOL)shouldAutorotate
{
     return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
      return UIInterfaceOrientationMaskPortrait;
}

任何人都可以建议这样做

提前致谢

2 个答案:

答案 0 :(得分:0)

这对我有用 我删除了NavigationController并更改如下

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        self.viewController = [[PlashViewController alloc] initWithNibName:@"PlashViewController" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
   [self.window makeKeyAndVisible];
   return YES;
}

我的应用程序将此方法放在我的视图控制器中,如下所示 在plist和target中我指定了三个方向,如肖像,landscapeleft和landscaperight 以纵向显示视图

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

以横向显示视图

 - (BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

答案 1 :(得分:0)

我发现只有rootviewcontroller在iOs 6中处理这些事情。在这里查看我的答案:https://stackoverflow.com/a/13033443/580173