最初在ios sdk中以横向模式打开视图控制器

时间:2012-12-11 06:58:58

标签: ios uiviewcontroller

我正在使用ios sdk 5

我正在从父视图控制器推送视图控制器,如此

DetailsViewController *detailController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil] ;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
[self.navigationController pushViewController:detailController animated:YES];

因为我想在横向模式下打开我的新控制器。我的父视图控制器处于potrait模式,所以我设置为

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

在我的孩子视图控制器中我已将其设置为

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

但是当我的子视图控制器打开时,它仍然会旋转到横向模式,但内部视图(如scrollview及其子视图)仍处于potrait模式。我已经阅读了很多类似的问题并尝试了它们,但没有一个能为我工作。请指出我如何在viewcontroller中旋转所有视图的正确方向

由于

1 个答案:

答案 0 :(得分:0)

只需替换方法,

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

通过

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     return  UIInterfaceOrientationIsPortrait(interfaceOrientation);
}