2015-05-25 63 views
0

我有我的應用程序在肖像模式。在風景和肖像中播放視頻

當視頻播放器進入全屏模式時,我想要以橫向和縱向播放該視頻。

moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; 
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)]; 

[moviePlayer setScalingMode:MPMovieScalingModeFill]; 

moviePlayer.view.frame = CGRectMake(0, 0, self.videoPlayerView.frame.size.width, self.videoPlayerView.frame.size.height); 
[self.videoPlayerView addSubview:moviePlayer.view]; 

我正在玩一個按鈕。

+0

什麼是您的rootViewController uinavigationcontroller或uitabbarcontroller? –

+0

問題的標題應該是關鍵的。並在問題的主體中使用一些解釋。 – Mrug

+0

你只是嘗試運行應用程序,然後轉動模擬器?或實際的設備? –

回答

0

啓用部署信息的景觀設備的方向。然後,在你的ViewController添加這些方法:

- (BOOL) shouldAutorotate { 
    return NO; 
} 

- (NSUInteger) supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationPortrait; 
} 
0

嘗試添加畫布視圖爲上海華到您的播放器和應用轉化爲畫布視圖。

- (void)initialize{  
    self.canvas = [[UIView alloc] initWithFrame: self.view.bounds]; 
    [self.view addSubview:self.canvas]; 

    // init moviePlayer 
    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; 
    ... 
    [self.canvas addSubview: moviePlayer.view]; 

    // Add observers 
    ... 
    [[NSNotificationCenter defaultCenter] addObserver: self 
        selector: @selector(deviceOrientationDidChange) 
         name: UIDeviceOrientationDidChangeNotification 
         object: nil]; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
} 

- (void)deviceOrientationDidChange{ 
    // Apply rotation only in full screen mode 
    if (self.isFullScreen) { 
     UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation; 

     [UIView animateWithDuration: 0.3 
         animations: ^{ 
      CGAffineTransform transform = CGAffineTransformMakeRotation(0); 
      switch (orientation) { 
       case UIDeviceOrientationLandscapeLeft: 
        transform = CGAffineTransformMakeRotation(M_PI_2); 
       break; 
       case UIDeviceOrientationLandscapeRight: 
        transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); 
       break; 
       default: 
       break; 
      }; 

      self.canvas.transform = transform; 
      self.canvas.frame = self.canvas.superview.bounds; 
     }]; 
    } 
}