2011-06-18 6 views
1

私はmpmovieplayerコントローラーで行うビデオを再生する必要があるアプリケーションを作成しています。ここでは両方向でこれを行う必要はありません。フレームが正しく設定されていません。私はどのchagesをコードで作成するために私が知っているようwrong.Pleaseだところを知らないiPadアプリの向きに問題がある

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self shouldAutorotateToInterfaceOrientation:[UIDevice currentDevice].orientation]; 

    NSURL *temp = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Floating" ofType:@"mp4"]]; 
    mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:temp]; 
    mpviewController.view.frame = CGRectMake(0, 0, 768, 1024); 
    mpviewController.view.backgroundColor = [UIColor clearColor]; 
    mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    mpviewController.view.userInteractionEnabled= NO; 
    mpviewController.moviePlayer.fullscreen= YES; 
    mpviewController.moviePlayer.controlStyle = MPMovieControlStyleNone; 
    [[mpviewController moviePlayer] play]; 

    [self.view addSubview:mpviewController.view]; 

} 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    currentOrientation = interfaceOrientation; 
    //[self SetInterface]; 

    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     mpviewController.view.frame = CGRectMake(0, 0, 768, 1024); 
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     mpviewController.view.frame = CGRectMake(0, 0, 1024, 768); 




    return YES; 
} 

をfollwsとして

コードがあります。適切な向きになるように。

Ragards Abhi

+0

@luzhin質問を編集してくれてありがとう、実際に私はこの問題がなぜ起こったのかという疑問を持つコードを追加する方法を知らない。 –

+0

これらのHTMLタグ「

 insert here your code
」を使用して質問にコードを追加することはできます – insumity

+0

@luzinありがとうございます。 –

答えて

1

まず です。あなただけshouldAutorotateToInterfaceOrientationでサポートさ方向を設定しshouldAutorotateToInterfaceOrientationで

セカンド

- あなただけ設定する必要があります。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     return YES; 
} 

それはあなたがビューのプロパティ変更それをしない用量場合 -

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)){ 
    //do what you want for portrait 
    }else{ 
    //do what you want for landscape 
    } 

} 
+0

プライベートメソッドを使用していません:setOrientation:UIDeviceOrientationPortrait animated:NO –

+0

いいえ、私はコードスニペットを提供できるなら同じ問題に直面しています偉大になる。 –

1

あなただけ返す必要がありYESまたはNO shouldAutorotateToInterfaceOrientation:方法では、それが唯一、お使いのコントローラでサポートされているの向きに関する情報を取得するための同じリンゴのドキュメントを読むためにフレームワークによって呼び出されます。

あなたorientationChanged:メソッドを実装し

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

notifictaion姿勢変更のために登録する必要があります。

//********** ORIENTATION CHANGED ********** 
- (void) orientationChanged:(NSNotification *)note 
{ 
    NSLog(@"Orientation has changed: %d", [[note object] orientation]); 
    //Put your code here from shouldAutorotateToInterfaceOrientation: 
} 

削除するのを忘れないでください。ここで

[[NSNotificationCenter defaultCenter] removeObserver:self]; 

私はあなたがそれだけでは自己サイズを変更しますようmpviewControllerのサイズを変更する必要はありません信じているいくつかのリンク

Device orientation - autorotate?

Orientation Changed Notification

+0

私はいくつかのコードスニペットを提供することができますが、私は試しても同じ結果が同じであっても、私はリンクを介して示唆した.Justでコード内のchagesを作る私は質問で誇らしげにし、私はこの時点で本当に立ち往生しています。 –

+0

本当に助けてくれたリンクのためにOKを行ったことがあります。 –

0

任意のコーディングを変更する必要はありませんが...簡単な挿入アプリケーションを次のようにコーディング、それが自動的に向きを検出します...

UINavigationBar * bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor blackColor]]; NSBundle * bundle = [NSBundle mainBundle];
NSString * moviePath = [bundle pathForResource:@ "sharkdivertrailer" of type:@ "mp4"];
NSURL * movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController * theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.view。フレーム= CGRectMake(184,200,400,300); [theMovie play];
MPMoviePlayerViewController * moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

関連する問題