【发布时间】:2014-07-22 21:40:30
【问题描述】:
我正在制作一个新闻应用程序,该应用程序的一个重要功能是提供可以播放视频的视图。所以我在 cocoacontrols.com 上查找并找到了这个控件:https://github.com/0xced/XCDYouTubeKit
我让这个插件运行良好,但现在问题开始了:
对于这个应用程序,方向需要始终是纵向的。没有风景或颠倒。这里的问题是您还需要观看纵向视频。没有人想要的东西吗?每个人都想横向观看视频!
现在我找到了一些对我有很大帮助的代码,并将XCDYouTubeVideoPlayerViewController 设置为可用于纵向和横向:
在我的 appDelegate 中添加以下代码:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[XCDYouTubeVideoPlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[UINavigationController class]]) {
// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];
// is at the top?
if ([nc.topViewController isKindOfClass:[XCDYouTubeVideoPlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
// or it's presented from the top?
} else if ([[nc.topViewController presentedViewController]
isKindOfClass:[XCDYouTubeVideoPlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
}
这段代码运行良好。视频可以纵向播放,也可以横向播放。 现在,当视频以横向结束或用户以横向结束视频并返回到他们来自应用程序的视图时,将以横向显示。我必须将我的设备转为纵向以便它会一直这样。
问题是:如何编辑上述代码,以便在视频以横向结束或用户以横向结束视频时禁用横向。它只需要在视频结束时恢复纵向并返回!
【问题讨论】:
-
正如我在回答中解释的那样,
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window不是指定方向的正确位置。首先,我怀疑您的应用程序中实际上有超过 1UIWindow。大多数应用程序没有。因此,您在不同的时间给supportedInterfaceOrientationsForWindow赋予不同的值会混淆iOS。您应该将该方法视为等同于plist: static。 -
我投票结束这个问题,因为它不再相关。代码过时的老问题。请删除此问题。
-
@Cœur 和其他亲密的选民:事实上,某些东西违反了某些其他网站的服务条款,甚至在某些司法管辖区是非法的,并没有使其本质上偏离-堆栈溢出的主题。请解释这个问题离题的正当理由。
-
@Cœur 根据模组无效:see this meta post
标签: objective-c xcode ios7 uiinterfaceorientation screen-rotation