简体   繁体   中英

How to add an Subview to a Fullscreen MPMoviePlayer

I want to add a Logo ( UIImageView ) to a fullscreen MPMoviePlayerController.

It works fine when the MPMoviePlayerController is not in fullscreen Mode. When i switch to full screen all added views on the MPMoviePlayerController removed(hidden).

Here is my code:

- (void)setupMPMoviePlayer{
    [self.moviePlayer.view removeFromSuperview];
    [self removeNotifications];
    self.moviePlayer = nil;

    self.moviePlayer = [[MPMoviePlayerController alloc] init];

    [self addNotifications];

    [self.moviePlayer.view setFrame:self.view.bounds];
    self.moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.moviePlayer.fullscreen = NO;
    [self.view addSubview:self.moviePlayer.view];


    if ([self.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)])
        [self.moviePlayer setAllowsAirPlay:YES];

    [self.moviePlayer setContentURL:[NSURL URLWithString:urlString]];
    [self.moviePlayer setFullscreen:YES animated:YES];
    [self addLogoViewAtView:self.moviePlayer.view];
}

- (void)addLogoViewAtView:(UIView *)view{        
    UIView *theView = [view viewWithTag:101];
    if (theView.superview) {
        [theView removeFromSuperview];
    }

    UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_weiss.png"]];
    logoView.tag = 101;
    logoView.frame = CGRectMake( logoView.image.size.width - 100.0,
                                100.0,
                                logoView.image.size.width,
                                logoView.image.size.height);
    logoView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;    
    [view addSubview:logoView];
    [view bringSubviewToFront:logoView];
}

Now my question is there an alternate way to add an subview to MPMoviePlayerController ?

I can add the logo to the application's window but this ist not so clean.

Anyone have any idea on how I could do this?

Most propably fullscreen mode add MPMoviePlayerController view at keyWindow for an application or present a modal view controller above. So, you can try looking for the view in window.subviews or modal view controllers for moviePlayer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM