【问题标题】:Play Landscape Video in iOS8 with Landscape Correct Statusbar Inside Portrait App在 iOS8 中使用纵向应用程序内的横向正确状态栏播放横向视频
【发布时间】:2014-09-26 12:08:19
【问题描述】:

纵向应用,加载横向显示的视频。

在 iOS7 中一切正常(小修这也是 iOS6),但在 iOS8 中状态栏,虽然在横向显示实际上以纵向状态栏的大小显示,所以它只占据视频的左上角 60%(如果横向握持设备)。

我使用的代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [planTitleLabel setText:[[ProgrammeHandler sharedHandler]
                             stringForElement:kPlanStringElementPlanTitle
                             onDay:0 inPlan:selectedPlan]];
}

- (NSUInteger)supportedInterfaceOrientations{
    return 0;
}

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];


    if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:FALSE];
        [[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:UIStatusBarAnimationNone];
    }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion floatValue] < 9.0) {
        [[UIApplication sharedApplication] setStatusBarHidden:TRUE];
    }


    NSString *moviePath = [[ProgrammeHandler sharedHandler] pathForAsset:kAssetVideoIntro onDay:0 forPlan:selectedPlan];
    CGSize screenBounds = [[UIScreen mainScreen] bounds].size;
    [whiteFadeView setFrame:CGRectMake(0, 0, screenBounds.width, screenBounds.height)];

    NSURL *videoURL = [NSURL fileURLWithPath:moviePath];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    [[moviePlayer view] setBackgroundColor:[UIColor blackColor]];
    [moviePlayer setControlStyle:MPMovieControlStyleNone];
    [moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
    //For viewing partially.....
    moviePlayer.view.transform = CGAffineTransformMakeRotation(M_PI/2);
    [moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
    [movieView setAlpha:0];

    [moviePlayer.view setFrame:[movieView frame]];
    moviePlayer.view.backgroundColor = [UIColor blackColor];

    [movieView addSubview:moviePlayer.view];

    [moviePlayer prepareToPlay];
    [moviePlayer play];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playbackFinished:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(hideControl)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:moviePlayer];

    [UIView animateWithDuration:0.5f delay:0.50f
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{[movieView setAlpha:1];} completion:^(BOOL fin){ }];
}

- (void) hideControl {
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerNowPlayingMovieDidChangeNotification
                                                  object:moviePlayer];
    [moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
}

我确实看到了这个问题,但认为它不适用于我的情况。 iphone: rotation in mpmovieplayercontroller?

有人知道如何将状态栏恢复为全屏“宽度”吗?

【问题讨论】:

    标签: xcode video ios8 orientation mpmovieplayercontroller


    【解决方案1】:

    好的,今天再次查看后,我注意到有一个错误,iOS7 似乎很满意,但它在 iOS8 中正确地抛出了一个错误。对于其他有相同问题的人:

    修复只是将转换应用到电影播放器​​本身而不是子视图。例如

    替换 moviePlayer.view.transform = CGAffineTransformMakeRotation(M_PI/2); 和 movieView.transform = CGAffineTransformMakeRotation(M_PI/2);

    【讨论】:

    • 谢谢,帮了我很多忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多