Ios 旋转时切换视图工作不正常
我一直在尝试几种方法以使旋转按预期工作,但到目前为止,我一直面临一些问题 现在我想要一个类,其中一个xib文件包含两个方向视图。一个是肖像画,一个是风景画 我正在我的主ViewController(应用程序委托中设置的根控制器)中尝试此操作。但不知怎的,它失败了:当我旋转时,视图被切换,但插座没有旋转。例如,横向视图中的简单标签将显示为设备处于纵向模式 下面是一些代码: 在我的应用程序代理中Ios 旋转时切换视图工作不正常,ios,ipad,rotation,Ios,Ipad,Rotation,我一直在尝试几种方法以使旋转按预期工作,但到目前为止,我一直面临一些问题 现在我想要一个类,其中一个xib文件包含两个方向视图。一个是肖像画,一个是风景画 我正在我的主ViewController(应用程序委托中设置的根控制器)中尝试此操作。但不知怎的,它失败了:当我旋转时,视图被切换,但插座没有旋转。例如,横向视图中的简单标签将显示为设备处于纵向模式 下面是一些代码: 在我的应用程序代理中 if ([[UIDevice currentDevice] userInterfaceIdiom] ==
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
//self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil withOrientation:UIInterfaceOrientationPortrait];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
在Viewcontroller.m中
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView2) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView2
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
self.view = self.landscapeView;
[[NSNotificationCenter defaultCenter] postNotificationName:@"landscape" object:nil];
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
self.view = self.portraitView;
[[NSNotificationCenter defaultCenter] postNotificationName:@"portrait" object:nil];
}
}
我打算使用本地通知将方向更改转发到Viewcontroller的子视图
不管怎样,我在这里错过了什么?我不明白为什么会失败。我发现当你打电话时
[UIDevice currentDevice].orientation
在
[viewController performSelector .....]
它不起作用
有没有人能解决这些问题