1

好的,所以我一直在测试我自己的在旋转时更改呈现的故事板的方法,并且一直在使用将-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation方法分配self给另一个运行 if-else 语句的方法来检查方向并适当地加载正确的故事板。我遇到的问题是检查它是否处于纵向模式或语句的 else 部分。当我在模拟器中运行应用程序并将设备旋转到横向时,它会像应该那样加载横向故事板。但是当我将设备旋转回纵向模式时,它不会变回纵向故事板。起初我认为问题在于我没有关闭视图控制器,但在这样做之后,它仍然无法正常工作。我意识到这是语句的 else 部分不起作用。NSLog(@"PMComplete")仍然在再次运行应用程序并旋转到横向并返回后,它仍然没有出现在日志中。有人对这里出了什么问题有任何想法吗?我在肖像故事板的视图控制器上操作这个(将肖像故事板中的视图控制器分配给 ViewController 类)。我还创建了这个没有情节提要的应用程序,并从头开始创建它们,并将肖像分配给从 AppDelegate 加载的那个。

这是我的 ViewController.m 文件:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize isLandscape;
@synthesize isPortrait;

- (void)viewDidLoad
{
    [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
}

-(void)viewChanged {

    UIInterfaceOrientation theOrientation = self.interfaceOrientation;
    UIStoryboard *portraitStoryboard;
    UIStoryboard *landscapeStoryboard;
    portraitStoryboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    landscapeStoryboard = [UIStoryboard storyboardWithName:@"LandscapeStoryboard" bundle:nil];
    UIViewController *portraitViewController = [portraitStoryboard instantiateInitialViewController];
    UIViewController *landscapeViewController = [landscapeStoryboard instantiateInitialViewController];

    if (theOrientation == UIInterfaceOrientationLandscapeLeft ||
        theOrientation == UIInterfaceOrientationLandscapeRight) {

        [portraitViewController dismissViewControllerAnimated:NO completion:nil];
        [self presentViewController:landscapeViewController animated:NO completion:nil];
        NSLog(@"LSComplete");


    }else{
        [landscapeViewController dismissViewControllerAnimated:NO completion:nil];
        [self presentViewController:portraitViewController animated:NO completion:nil];
        NSLog(@"PMComplete");
    }

}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

    [self viewChanged];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

0 回答 0