【问题标题】:MPMoviePlayerController should only in landscape modeMPMoviePlayerController 应该只在横向模式下
【发布时间】:2012-10-22 12:15:10
【问题描述】:

我在我的应用程序中使用 MPMoviePlayerController 来播放视频。我的应用程序仅在纵向模式下工作。我希望应用程序视频只能在横向模式下播放。所以请任何人建议我如何做到这一点。现在我的视频正在纵向模式下播放。

【问题讨论】:

    标签: iphone ios ipad mpmovieplayercontroller uiinterfaceorientation


    【解决方案1】:

    为此,您需要继承 MPMoviePlayerController 类。

    @interface yourMovie:MPMoviePlayerController
    {
    }
    @end
    

    并且你需要在实现中实现shouldAutoRotate方法并且只返回横向模式

    @implementation yourMovie
    
    - (BOOL)shouldAutorotate
    {
        return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
    }
    @end
    

    您需要创建yourMovie 实例而不是MPMoviePlayerController

    【讨论】:

    • 感谢您的快速答复。但它在 iOS 6 中不起作用。请你为我提供 iOS 6。thx
    • @MiteshKhatri:我在 iOS 6 上使用了相同的代码。还要检查从创建电影播放器​​的父视图的 shouldRotate 方法中返回 yes
    • 我检查了,应用程序支持的方向只有纵向,我只想要横向的播放器。我也尝试了上面的代码,但它对我不起作用。谢谢
    • @MiteshKhatri:请检查此链接,它可能对您有所帮助...stackoverflow.com/questions/1374558/…
    • 嗨,@Midhun MP,我尝试了一切,但对我没有用。因此,请您建议我如何在应用程序仅处于纵向模式时以横向模式显示视频。谢谢
    【解决方案2】:

    在您的 MPMoviePlayerController 中使用此代码,

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    

    您也可以使用UIInterfaceOrientationLandscapeRight 而不是UIInterfaceOrientationLandscapeLeft...

    【讨论】:

    • 感谢您的快速答复。但它在 iOS 6 中不起作用。请你为我提供 iOS 6。thx
    • 在 xcode 中,“摘要”下有一个选项是“支持的设备方向”,在该选项中选择横向选项....我不确定 ios6 中的这个...但是试试这个。 .
    • 它在 iOS 5 中运行良好,但在 iOS 6 中却不行。所以如果您有任何想法,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多