3

我的整个应用程序都有视频。一些使用 MPMoviePlayerController,另一些使用 YouTube 的 UIWebView。我希望我的应用程序完全是纵向的。但是,我想让用户选择在有视频时翻转到横向(不是强制,而是可选)。

我一直在网上搜索答案,但我还没有找到任何答案。

谢谢你的帮助!

4

5 回答 5

7

I had the same issue and fixed it by adding this in my app delegate, basically allowing Landscape orientation only on subclasses of MPMoviePlayerViewController:

#import <MediaPlayer/MediaPlayer.h>

@implementation UIViewController (orientationFix)

-(NSUInteger) supportedInterfaceOrientations
{
    if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
        return UIInterfaceOrientationMaskLandscape;
    }
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
        return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }
    return UIInterfaceOrientationPortrait;
}

@end

@implementation MyAppDelegate
.
.
.
@end
于 2014-08-12T23:58:29.347 回答
0

要么子类化它 -

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation { //在此处返回风景 } 对于 ios6: shouldAutorotate return no

或者

用这个:

MPMoviewPlayerController 全屏播放旋转,底层 UIViewController 仅具有纵向模式(不允许旋转)

于 2013-06-18T23:03:02.397 回答
0

将此添加到应用程序委托中。

-(BOOL)shouldAutorotate
    {
        return NO; 
    }

-(NSUInteger)supportedInterfaceOrientations
{
    //LandScapeMode:- UIInterfaceOrientationMaskLandscape;
    //PortraitMode:- 
    return UIInterfaceOrientationMaskPortrait 
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //LandScapeMode:- UIInterfaceOrientationLandscapeRight;
   // ProtraitMode:-
   return UIInterfaceOrientationPortrait
}
于 2016-05-26T12:58:48.997 回答
0

在 AppDelegate 中添加这些行。

-(BOOL)shouldAutorotate { return NO; }

-(NSUInteger)supportedInterfaceOrientations
{
    //LandScapeMode:- UIInterfaceOrientationMaskLandscape;
    //PortraitMode:- 
    return UIInterfaceOrientationMaskPortrait 
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //LandScapeMode:- UIInterfaceOrientationLandscapeRight;
   // ProtraitMode:-
   return UIInterfaceOrientationPortrait
}
于 2016-05-26T12:48:07.730 回答
0
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.view.transform = CGAffineTransformConcat(self.moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[self.moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:self.moviePlayer.view];
[self.moviePlayer play];
于 2016-08-26T05:09:37.217 回答