Objective c 屏幕旋转赢得';t旋转回原始状态

Objective c 屏幕旋转赢得';t旋转回原始状态,objective-c,xcode,ios7,uiinterfaceorientation,screen-rotation,Objective C,Xcode,Ios7,Uiinterfaceorientation,Screen Rotation,我正在制作一个新闻应用程序,该应用程序的一个重要功能是可以观看视频。所以我在cocoacontrols.com上找到了这个控件: 我让这个插件工作正常,但现在问题开始了: 对于此应用程序,方向需要始终为纵向。没有景观或倒置。这里的问题是,你还需要看一个视频的肖像。没人想要的东西,对吧?每个人都想看风景中的视频 现在我找到了一些对我很有帮助的代码,并设置了可用于纵向和横向的xcdyoutubevideoplayervewcontroller: 在我的appDelegate中,我添加了以下代码: -

我正在制作一个新闻应用程序,该应用程序的一个重要功能是可以观看视频。所以我在cocoacontrols.com上找到了这个控件:

我让这个插件工作正常,但现在问题开始了:

对于此应用程序,方向需要始终为纵向。没有景观或倒置。这里的问题是,你还需要看一个视频的肖像。没人想要的东西,对吧?每个人都想看风景中的视频

现在我找到了一些对我很有帮助的代码,并设置了可用于纵向和横向的
xcdyoutubevideoplayervewcontroller

在我的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
{

    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;
            }
        }
    }
}
application:supportedInterfaceDirectionsforWindow:

此方法返回应用程序支持的界面方向的总集。确定是否旋转特定视图控制器时,此方法返回的方向与根视图控制器或最顶端显示的视图控制器支持的方向相交。在允许旋转之前,应用程序和视图控制器必须一致

如果未实现此方法,应用程序将使用应用程序Info.plist的UIInterfaceOrientation键中的值作为默认界面方向

您应该改为使用此选项:

-(NSUInteger)在您的
UIViewController中支持接口方向


当用户更改设备方向时,系统会在根视图控制器或填充窗口的最上面显示的视图控制器上调用此方法。如果视图控制器支持新方向,则窗口和视图控制器将旋转到新方向。仅当视图控制器的shouldAutorotate方法返回YES时,才会调用此方法。

-(NSUInteger)应用程序中:SupportedInterfaceDirectionsforWindow
,将“self.window”替换为“window”。

正如我在回答中解释的那样,
-(NSUInteger)应用程序:(UIApplication*)应用程序支持的InterfaceDirectionsforWindow:(UIWindow*)窗口
不是指定方向的正确位置。对于初学者,我怀疑您的应用程序中是否有超过1个
UIWindow
。大多数应用程序都没有。因此,您在不同的时间为Windows支持的界面方向赋予不同的值,从而混淆了iOS。您应该将该方法视为与
plist
:static等效的方法。此处放置聊天:我投票结束此问题,因为它不再相关。代码过时的老问题。请删除这个问题。@Cœur和其他亲密的投票者:事实上,某些内容违反了其他网站的TOS,甚至在某些司法管辖区是非法的,但这并不意味着堆栈溢出本身就是离题的。请解释这个问题离题的合理原因。@Cœu根据mods无效:你也可以从另外两个答案中得到启发:它们涵盖了你的所有入职需求:我的回答我理解你的答案和我应该做什么,但它根本不起作用。基本上你说的是:删除所有代码。转到视图控制器,其中视图应始终是纵向的,并放置以下代码:-(NSUInteger)SupportedInterfaceOrientationMaskPortrait;}或???基本上是:每个视图控制器负责其方向。嗯,当我尝试将该代码添加到每个视图时,它不起作用。视图不会在XCDYouTubeVideoPlayerViewController上旋转。让我们聊聊,这样我就可以解释我的工作了!不起作用。当我关闭视频时,视图将停留在景观中。。。。