【问题标题】:Switching views upon rotation not working properly旋转时切换视图无法正常工作
【发布时间】:2012-10-17 09:34:53
【问题描述】:

我一直在尝试几种方法来使轮换按预期工作,但到目前为止我一直面临一些问题。

现在我想要一个类,其中包含一个包含 2 个方向视图的 xib 文件。一张纵向,一张横向。

我正在我的主 ViewController 中尝试这个(应用程序委托中设置的根控制器。但不知何故它失败了:当我旋转时,视图被切换但插座没有旋转。例如,来自横向视图的简单标签将显示为设备处于纵向模式。

这里有一些代码:

在我的应用委托中

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 的子视图。

无论如何,我在这里缺少什么?我不明白为什么会失败。

【问题讨论】:

    标签: ios ipad rotation


    【解决方案1】:

    我发现当你打电话时

    [UIDevice currentDevice].orientation
    

    的上下文中
    [viewController performSelector .....]
    

    没有用。

    一些机构可以解决这些问题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多