2

我的情况与这个问题非常相似。我有一个通用的应用程序,其中 iPhone 为纵向,iPad 为横向,我使用 appDelegate.window.rootViewController = newScreen 在所有主屏幕之间切换;iPhone 应用程序完美运行。iPad应用程序有时会以纵向而不是横向将屏幕弹出。这是一些示例转换代码:

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
            ViewController* v = nil;
            if (IS_IPAD()) {
                v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
            }else{
                v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
            }
            [appDelegate.window setRootViewController:(UIViewController*)v];

我也从另一个问题中尝试过这个:

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
            ViewController* v = nil;
            if (IS_IPAD()) {
                v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
            }else{
                v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
            }

            [UIView
             transitionWithView:appDelegate.window 
             duration:0.5
             options:UIViewAnimationOptionTransitionCrossDissolve
             animations:^(void) {
                 BOOL oldState = [UIView areAnimationsEnabled];
                 [UIView setAnimationsEnabled:NO];
                 [appDelegate.window setRootViewController:(UIViewController*)v];
                 [UIView setAnimationsEnabled:oldState];
             } 
             completion:nil];

但没有什么能解决它。

还尝试使用 [appDelegate.window makeKeyAndVisable] 和 [appDelegate.window makeKeyWindow],希望这会“震撼”它做出正确的方向。

4

1 回答 1

4

我懂了!

这是我的过渡块的样子。我做的关键是从 CALayer 复制变换(进行实际旋转的东西)。请注意,您必须#import <QuartzCore/QuartzCore.h>在文件顶部包含 Quartz 框架。

[UIView transitionWithView:self.window 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionCrossDissolve 
                animations:^{                        
    BOOL oldState = [UIView areAnimationsEnabled];
    [UIView setAnimationsEnabled:NO];
    target.view.layer.transform = window.rootViewController.view.layer.transform;
    window.rootViewController = target;
    [UIView setAnimationsEnabled:oldState];
} completion:nil];
于 2012-07-09T21:57:50.170 回答