代码之家  ›  专栏  ›  技术社区  ›  Joson Daniel

在iOS中点击全屏按钮时,可以强制MPMoviePlayerController横向移动

  •  5
  • Joson Daniel  · 技术社区  · 11 年前

    我在detailView(UIVIew)中创建了一个MPMoviePlayerController,现在我想在用户单击全屏按钮时强制MPMoviePlayerController为横向视图。我能做到吗?请给我任何建议。提前谢谢。这是我要创建的代码:

       NSURL *movieURL = [NSURL URLWithString:previewString];
        movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
        [movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
        movieController.view.backgroundColor = [UIColor grayColor];
        [detailview addSubview:movieController.view];
        [movieController prepareToPlay];
        movieController.shouldAutoplay = NO;
    

    并将进入全屏()功能:

        - (void)willEnterFullscreen:(NSNotification*)notification {
        NSLog(@"willEnterFullscreen");
        donepress = YES;
        // nothing
    }
    

    我试着搜索,但仍然没有任何好的答案。请帮帮我。非常感谢

    1 回复  |  直到 11 年前
        1
  •  12
  •   JoeyJAL    11 年前

    是的,您可以使用两个通知观察员来更改整个方向。

    首先,在您的AppDelegate didFinishLaunchingWithOptions方法中添加两个通知观察员:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    

    第二,添加方法和属性

    - (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
        self.allowRotation = YES;
    }
    - (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
        self.allowRotation = NO;
    }
    

    第三,覆盖支持的InterfaceOrientationsForWindow方法,您可以返回您想要的任何方向

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if (self.allowRotation) {
            return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
        }
        return UIInterfaceOrientationMaskPortrait;
    }