【问题标题】:Need help fixing orientation for certain UIViewControllers需要帮助修复某些 UIViewControllers 的方向
【发布时间】:2016-11-12 13:02:07
【问题描述】:

我正在构建一个包含多个屏幕的视频应用程序,我希望所有这些屏幕都只允许纵向除了视频播放器屏幕可以手动从纵向切换到横向。 p>

现在我在视频播放器屏幕中有以下内容

#pragma mark - CHANGE ORIENTATION METHODS


- (void)changeOrientation {

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

}

然后在列表屏幕中,我尝试将方向固定为仅纵向。

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

现在,当我加载应用程序时,它似乎将方向设置为纵向,问题出在视频播放器屏幕上,我有一个后退按钮。如果该屏幕处于横向模式并且我单击返回

shouldAutorotateToInterfaceOrientation

没有被调用并且卡在横向模式。

如何强制它调用上述方法,或者有更好的方法来解决这个问题?谢谢

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    您可以尝试以编程方式强制更改方向:

    -(void)viewWillAppear:(BOOL)animated {
       NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
       [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
    

    当然,您需要在项目目标->部署信息->设备方向中启用横向。希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2014-07-19
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 2019-07-24
      相关资源
      最近更新 更多