Iphone iOS-旋转时更改故事板-肖像问题
好的,所以我一直在测试我自己在旋转时改变呈现的故事板的方法,并且一直在使用Iphone iOS-旋转时更改故事板-肖像问题,iphone,ios,objective-c,xcode,Iphone,Ios,Objective C,Xcode,好的,所以我一直在测试我自己在旋转时改变呈现的故事板的方法,并且一直在使用-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation方法将self分配给另一个方法,该方法运行if-else语句,检查方向并适当加载正确的故事板。我遇到的问题是检查它是否处于纵向模式或语句的其他部分。当我在模拟器中运行应用程序并将设备旋转到横向时,它会像应该的那样加载横向故事板。但当我将设备旋转回纵
-(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
我建议您使用一个viewcontroller,只需操纵帧即可。