好的,所以我一直在测试我自己的方法,在轮换时更改演示的故事板,并且已经使用-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
方法将self
分配给另一个运行if-else的方法用于检查方向并正确加载正确故事板的语句。我遇到的问题是检查它是处于纵向模式还是声明的其他部分。当我在模拟器中运行应用程序并将设备旋转到横向时,它会加载风景故事板。但是当我将设备旋转回纵向模式时,它不会变回肖像故事板。起初我认为问题是我没有解雇视图控制器,但在这之后,它仍然无法工作。我意识到这是声明的其他部分无效。我卡住NSLog(@"PMComplete")
但仍然在再次运行应用程序并旋转到横向和后退之后,它仍然没有显示在日志中。有没有人对这里的错误有什么想法?我在肖像故事板的viewcontroller上操作它(在肖像故事板中为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