UIOrientation加载查看错误的方式

时间:2010-09-09 09:57:49

标签: iphone cocoa-touch

我有一个tabBarViewController,当在标签0中时,用户可以水平转动设备并显示landscapeViewController。在横向视图控制器中,我需要能够使用按钮加载不同的全屏视图,具体取决于用户希望看到的内容。它适用于某一点但随后混淆了。基本上当用户第一次旋转时,视图被正确加载,但是当viewController尝试加载第二个横向视图时,它不会重新定位此视图中的元素,只有状态栏?如果我然后旋转到另一个景观orietnation它自己排序?有谁知道我做错了什么?

以下是我的一些代码

-(void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}

-(void)detectOrientation {
   if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) 
      [delegate landscapeViewController:self didRotateBack:YES]; 

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(IBAction)showSecondLandscapeView {
    self.view = secondLandscapeView;
}

非常感谢

编辑:我还应该提一下,landscapeViewController是以模态方式呈现的,不确定这是否会产生任何不同。

1 个答案:

答案 0 :(得分:0)

好的,如果我将self.view = secondView更改为[self.view addSubview:secondView]它会有效。