2012-11-28 46 views
0

我想添加一個Logo(UIImageView)到全屏MPMoviePlayerController。如何將子視圖添加到全屏MPMoviePlayer

MPMoviePlayerController未處於全屏模式時,它工作正常。當我切換到全屏時,MPMoviePlayerController上的所有添加視圖都被刪除(隱藏)。

這裏是我的代碼:

- (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]; 
} 

現在我的問題是有一個子視圖添加到MPMoviePlayerController的替代方法?

我可以將徽標添加到應用程序的窗口,但這並不是那麼幹淨。

任何人對我如何做到這一點有任何想法?

回答

0

大多數全屏模式在應用程序的keyWindow中添加MPMoviePlayerController視圖,或者呈現上面的模式視圖控制器。因此,您可以嘗試在window.subviews或moviePlayer的模式視圖控制器中查找視圖。

+0

你有上面介紹模態viewController的示例嗎?我已經測試過它,但它不起作用。 – Zeropointer