Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 视图控制器:Ladnscape到纵向_Iphone_Ios_Ipad - Fatal编程技术网

Iphone 视图控制器:Ladnscape到纵向

Iphone 视图控制器:Ladnscape到纵向,iphone,ios,ipad,Iphone,Ios,Ipad,我的应用程序中有一个视图控制器。让它的第一个视图控制器,我的第一个视图控制器出现在手机的纵向模式下,当用户在横向模式下旋转手机时,第一个视图控制器也在横向模式下旋转 工作正常,现在我在第一视图控制器上有一个按钮,当我触摸按钮时,第二视图控制器出现。我只想做的是,第二个视图控制器应始终以纵向模式显示,即使第一个视图控制器处于横向模式。 是否有任何方法必须重写才能获得此功能?在导航控制器中,控制器的方向取决于导航控制器根控制器的方向 你有两种可能: 使根控制器的shouldAutorotateToI

我的应用程序中有一个视图控制器。让它的第一个视图控制器,我的第一个视图控制器出现在手机的纵向模式下,当用户在横向模式下旋转手机时,第一个视图控制器也在横向模式下旋转

工作正常,现在我在第一视图控制器上有一个按钮,当我触摸按钮时,第二视图控制器出现。我只想做的是,第二个视图控制器应始终以纵向模式显示,即使第一个视图控制器处于横向模式。
是否有任何方法必须重写才能获得此功能?

在导航控制器中,控制器的方向取决于导航控制器根控制器的方向

你有两种可能:

  • 使根控制器的
    shouldAutorotateToInterfaceOrientation:
    根据实际显示的控制器返回不同的值

  • 对视图控制器的视图使用变换,使其旋转

  • 我会尝试第一种方式,开始。看一看如何操作(忽略
    UITabBarController
    之类的东西),或者试试这个(它只是将消息传递给导航层次结构中的顶级控制器):

    为了在iOS6上获得相同的结果,请尝试并定义以下方法:

    -(NSUInteger)supportedInterfaceOrientations {
      return [self.navigationController.topController supportedInterfaceOrientations];
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
      return [self.navigationController.topController  preferredInterfaceOrientationForPresentation];
    }
    

    在“第二视图控制器”中保留此项。

    两个视图控制器是如何连接的(例如,导航控制器等)?基本上我使用导航控制器进行连接。
    [self.navigationController pushViewController:secondViewController动画:是]我使用此方法连接它们。先生,我使用的是ios6。我创建了UINavigationController的控制器子类。ios6中不推荐使用上述方法。所以我用了shouldAutorotate方法。然后我使用我的第一个视图控制器作为导航控制器的根视图控制器。但是它不起作用,先生。虽然不推荐使用,但如果你想让你的应用程序在iOS5上运行,你仍然需要
    shouldAutorotateToInterfaceOrientation
    ——我只是想你会对iOS6方法应用同样的推理(我还没有在本文中使用过)。在任何情况下,请检查我的编辑以获得解决方案的iOS6版本。我希望它能起作用,但正如我所说,我还没有试过。
    -(NSUInteger)supportedInterfaceOrientations {
      return [self.navigationController.topController supportedInterfaceOrientations];
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
      return [self.navigationController.topController  preferredInterfaceOrientationForPresentation];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
       // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }