【问题标题】:Objective-C change device orientation for only one UiViewControllerObjective-C 仅更改一个 UiViewController 的设备方向
【发布时间】:2016-03-02 13:00:58
【问题描述】:

我只想为一个 UiViewController 更改设备方向。我的第一个 UiViewController 的名字是 VideoLaunch。我首先想要这个 UiViewController 中的横向方向。当我传递另一个 uiviewcontroller 时,我将一个名为“is”的静态值更改为与 nil 不同。当我在调试模式下运行时,我看到了

否则返回 UIInterfaceOrientationMaskPortrait

这条线运行。但方向没有改变。

AppDelegate.m

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {   
    if([VideoLaunch is] == nil)
        return UIInterfaceOrientationMaskLandscape;

    else return UIInterfaceOrientationMaskPortrait;
 }

【问题讨论】:

标签: objective-c iphone device-orientation


【解决方案1】:

你需要重写下面的方法

- (BOOL)shouldAutoRotate

为您希望允许旋转的那个返回 YES。

然后,还覆盖supportedDeviceOrientations 并在其中指定您想要的内容。例如:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

并确保您在目标的常规设置中正确允许方向。

【讨论】:

  • Xcode 7 后使用(UIInterfaceOrientationMask)supportedInterfaceOrientations
猜你喜欢
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-08
  • 2018-11-25
  • 1970-01-01
相关资源
最近更新 更多