gpt4 book ai didi

ios - UIWebview -- "Open/Copy"对话框以错误的方向打开

转载 作者:行者123 更新时间:2023-11-29 13:42:39 26 4
gpt4 key购买 nike

我正在用旋转做一些奇特的事情,并从 shouldAutorotateToInterfaceOrientation: 返回 NO。然后,我根据 [UIDevice currentDevice].orientationCached 手动旋转 UIWebView。当我在链接上按住手指时,出现的菜单始终为 PortraitLeft 方向,无论设备的实际方向如何,也无论 UIWebView 的方向如何。

在我看来,链接菜单的方向来自 View Controller 的主视图,而不是与其相关联的 UIWebView,并且使其正确运行的唯一方法是从 -shouldAutorotateToInterfaceOrientation: 返回 YES

这个假设是否正确?有什么方法可以控制与链接相关的弹出菜单的方向,或者强制它从生成它的 UIWebView 获取方向?

最佳答案

我实际上不会像您在 UIWebView 中那样手动设置方向。相反,通过代码强制父 View Controller 的方向。

作为类似情况的示例,我开发了一个应用程序,它可以在几个 View 中显示 map 。当从纵向旋转到横向时,它以与带有精美动画的纵向布局截然不同的方式布局 View 。我喜欢它,但有些用户不喜欢,所以我提供了禁用 map 旋转的选项。我通过仅将某些旋转功能传递给父 View 来做到这一点。因此,如果他们禁用横向,我会告诉 parent View Controller 它只能旋转到横向。否则,它可以自由旋转到除倒置之外的任何方向。

解释够了:这是我用来完成此操作的相关代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
//Rotate the view if rotation is actually enabled
if ([self.prefs boolForKey:@"SHOULD_ROTATE"]) {
return (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) || UIInterfaceOrientationPortrait == toInterfaceOrientation);
}

//Rotate it to portrait only if rotation is disabled
else if (![self.prefs boolForKey:@"SHOULD_ROTATE"]) {
return (UIInterfaceOrientationPortrait == toInterfaceOrientation);
}

//Otherwise, rotate only to portrait (for all views minus the map views)
else {
return (UIInterfaceOrientationPortrait == toInterfaceOrientation);
}
}

我实际上在 UITabBarController 中实现了它,因此它适用于应用程序中的所有 View 和 View Controller ,但它只对 UIWebView 父 View 很容易实现 Controller 。要点是,根据 View 方向是否与您想要的相匹配,您将返回是或否。对于 WebView ,您可能希望通过返回以下内容来布置唯一允许的旋转方向:

return (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)

当然,我没有讨论强制 View 将 View 设置为横向 View ,只讨论了用户转动它时它会做什么。因此,最好的做法是在 View 初始化后手动执行此操作:

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO]

开始时,您必须将其设置为 LeftRight,但如果您实现我之前的代码,用户可以根据需要在左右之间旋转代码也是如此。

解释太多了,但我认为父 View Controller 的这两种方法的组合应该允许您完全按照自己的意愿呈现 View 。如果您有任何问题,请告诉我!

关于ios - UIWebview -- "Open/Copy"对话框以错误的方向打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8671744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com