【发布时间】:2014-12-23 07:08:53
【问题描述】:
我有一个 UIWebView 包含在 UIViewController 中,它是 UINavigationController 的后代。它看起来像这样:
该应用程序仅是纵向的。当我播放视频时,我希望用户能够旋转设备并以横向模式观看视频。我使用此代码来允许它:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
id presentedViewController = [self topMostController];
NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
if ([className isEqualToString:@"MPInlineVideoFullscreenViewController"] ||
[className isEqualToString:@"MPMoviePlayerViewController"] ||
[className isEqualToString:@"AVFullScreenViewController"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIViewController *)topMostController {
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
然后在我的 UINavigationController 中(所以当视频结束时,视图不会以横向呈现,而只会以纵向呈现):
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
一切正常:
但随后视频播放完毕(或用户点击“完成”)并且屏幕返回到底层视图,这就是发生的情况:
如您所见,导航栏滑到状态栏下方。 此外,我在日志中收到很多自动布局错误:http://pastebin.com/09xHzmgJ
知道如何解决这个问题吗?
【问题讨论】:
-
你的项目中有哪些设置(代码之外?)
-
@entropid 你有没有为此打开过雷达?在 iOS 10 上仍然是一个问题...
标签: ios objective-c uiwebview uinavigationcontroller screen-rotation