【问题标题】:Open view controller in Landscape mode initially in ios sdk最初在 ios sdk 中以横向模式打开视图控制器
【发布时间】:2012-12-11 06:58:57
【问题描述】:

我正在使用 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;
    }

但是,当我的子视图控制器打开时,它仍会旋转到横向模式,但内部视图(如滚动视图及其子视图)仍处于 potrait 模式。我已经阅读了很多类似的问题并尝试了它们,但它们都不适合我。请指出正确的方向,以了解如何在 viewcontroller 中旋转所有视图

谢谢

【问题讨论】:

    标签: ios uiviewcontroller


    【解决方案1】:

    只需替换方法,

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

    由,

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

    【讨论】:

    • 我试过 K.D 但它仍然没有旋转滚动视图及其内部视图。
    • 如果你希望你的视图是横向而不是返回 UIInterfaceOrientationILandscape(interfaceOrientation); , 并在 .plist 文件中仅设置横向方向并从中删除其他方向。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多