iPad MPMoviePlayerController - Disable Fullscreen

2019-01-14 16:54发布

Is there a way to disable the fullscreen button of the MPMoviePlayerController ?

16条回答
ら.Afraid
2楼-- · 2019-01-14 17:15

If the only thing you want to do is disable pinch to go full screen (i.e. keep interaction enabled and whatever control style you want), you can use this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    NSSet *set = [event allTouches];
    NSArray *arr = [set allObjects];
    for (int i = 0; i < arr.count; i++) {
        UITouch *touch = (UITouch *) [arr objectAtIndex:i];

        NSArray *recognisers = touch.gestureRecognizers;
        for (UIGestureRecognizer *recogniser in recognisers) {
            if (recogniser.enabled && [recogniser isMemberOfClass:[UIPinchGestureRecognizer class]]) {
                recogniser.enabled = NO;
            }
        }
    }
}
查看更多
Summer. ? 凉城
3楼-- · 2019-01-14 17:17

Depending on your needs, you can also simply disable all user interactions on the player view.

player.view.userInteractionEnabled = NO;
查看更多
再贱就再见
4楼-- · 2019-01-14 17:23

You can set controlStyle to Fullscreen. these controls are somewhat different, but it doesn't feature a Fullscreen button!

[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
查看更多
姐就是有狂的资本
5楼-- · 2019-01-14 17:23

I know, it's a little outdated, but anyway. I did some research in that direction, and looks like a found an answer. I do not know, why it's working, but it is.

-(void) playMovieAtURL: (NSURL*) theURL {

    MPMoviePlayerController* theMovie =
    [[MPMoviePlayerController alloc] initWithContentURL: theURL];
    //That line is for ARC. Without it, it may not work.
    self.moviePlayer = theMovie;
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    theMovie.controlStyle = MPMovieControlStyleFullscreen;
    theMovie.repeatMode  = MPMovieRepeatModeOne;
    //Here you'd better use your custom ViewController subclass, if you want autorotating and all that stuff.
    UIViewController * vc = [UIViewController new];
    [vc.view addSubview:theMovie.view];
    theMovie.fullscreen  = YES;
    theMovie.view.frame = vc.view.bounds;
    vc.view = theMovie.view;
    [self presentModalViewController:vc animated:YES];
    theMovie.fullscreen  = YES;

    [theMovie prepareToPlay];
    [theMovie play];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}

// When the movie is done, release the controller.

-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
    [self dismissModalViewControllerAnimated:YES];
    MPMoviePlayerController* theMovie = [aNotification object];
    [[NSNotificationCenter defaultCenter]
 removeObserver: self
 name: MPMoviePlayerPlaybackDidFinishNotification
 object: theMovie];
    [self.moviePlayer.view removeFromSuperview];
    self.moviePlayer = nil;
    // Release the movie instance created in playMovieAtURL:
}
查看更多
Rolldiameter
6楼-- · 2019-01-14 17:24

There's a cheat:

MPMoviePlayerController *mpc = (...some instance...)
UIView *fsbutton = [[mpc view] viewWithTag:512];
[fsbutton setHidden:YES];

The main catch is, you have to do it in viewDidAppear: or similar, because the MoviePlayer view sets itself up somewhere inside didMoveToWindow or didMoveToSuperview, which happen after viewWillAppear:. So you get a brief flash of the fullscreen button. Other obvious catches include: brittle vs. Apple changing that 512 tag value (although it works in 3.2 - 4.2); and of course Apple would rather you not do this.

The endorsed solution is to set the control style to MPMovieControlStyleNone and roll your own transport controls, which is more work.

查看更多
该账号已被封号
7楼-- · 2019-01-14 17:24

Simple block to remove pinch zoom here

Hope it help

it work with me on iOS6

 for (UIView *view in  moviePlayer.view.subviews) {

    for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
    if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
        [view removeGestureRecognizer:pinch];
    }
}
查看更多
登录 后发表回答