【问题标题】:App rotating to landscape left and right, when landscape "right" is explicitly chosen. Xcode 7.2.1当明确选择横向“右”时,应用程序向左和向右旋转。 Xcode 7.2.1
【发布时间】:2016-02-26 03:48:04
【问题描述】:

谁能告诉我为什么会这样?还有其他需要定义的地方吗?

//AppDelegate

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    //return NO;
}

-(BOOL)shouldAutorotate {
    return NO;
}

【问题讨论】:

  • 您有评论//AppDelegate。应用程序委托的 supportedInterfaceOrientations 从未被调用(其他方法也没有),因此该代码无效。
  • 那只是为了显示代码在哪里。但你只是让我看得更远,向我展示了我的错误……对不起,发布了如此愚蠢的错误。我在 AppDelegate 中也有这个 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{}
  • 返回的是 Landscape 而不是 LandscapeRight。谢谢你指出我的愚蠢。谢谢! @马特
  • 酷。随意将其发布为您自己问题的答案:在 SO 上完全合法(并鼓励)。你问还有什么地方会对轮换产生影响,你找到了!

标签: ios objective-c xcode7 uiinterfaceorientation


【解决方案1】:

我在我的应用委托中发现了另一种界面定向方法。感谢@matt 的评论,这让我更加仔细地看了看。它正在返回风景,将其更改为风景,现在一切都很好。

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (([window.rootViewController.presentedViewController isKindOfClass:[UIImagePickerController class]]) && (window.rootViewController.presentedViewController.isBeingDismissed == NO)) {
    return UIInterfaceOrientationMaskPortrait;
}
//return UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskLandscapeRight;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2019-04-16
    • 2017-03-05
    • 1970-01-01
    相关资源
    最近更新 更多