3

このコードを ViewController に追加しました。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation != UIInterfaceOrientationPortrait) {
    [self.moviePlayerController setFullscreen:YES animated:YES]; 
} 
return YES;
}

したがって、回転後、プレーヤーはフルスクリーンモードでビデオを再生します。setFullScreen:NO には、playerController (OrientationPortrait) で回転イベントをキャッチする必要があります。これどうやってするの?回答ありがとうございます。

4

1 に答える 1

3

moviePlayerController の向きの設定は、この関数では処理しないでください。

viewWillAppear 関数に通知機能を追加する

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

向きの変更は、この関数に通知します

- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

これは、moviePlayerController フレームの向きが処理されるこの関数を呼び出します。

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    [self.moviePlayerController setFullscreen:NO animated:YES];    
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{
    [self.moviePlayerController setFullscreen:YES animated:YES]; 
}}

viewDidDisappear で通知を削除する

-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}
于 2012-08-22T14:02:14.590 に答える