0

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

有人可以建议这样做吗

提前致谢

4

2 回答 2

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 和目标中,我指定了三个方向,如纵向、横向左和横向右 以显示纵向视图

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

以横向显示视图

 - (BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
于 2012-12-14T07:44:33.587 回答
0

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

于 2012-12-14T07:47:38.573 回答