1

mpmovieplayer コントローラーで行うビデオを再生する必要があるアプリケーションを作成しています。これを両方の向きで行う必要があります。しかし、フレームが正しく設定されません。

コードは次のとおりです

// 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;
}

どこが間違っているのかわかりません。コードを変更する必要がある場合はお知らせください。適切な方向性を得るために。

ラガーズ・アビ

4

3 に答える 3

1

メソッドでYES または NO のみを返す必要があります。shouldAutorotateToInterfaceOrientation:フレームワークによって呼び出されるのは、コントローラーでサポートされている方向に関する情報を取得するためだけです。同じことについては、Apple のドキュメントを参照してください。

オリエンテーション変更届の登録が必要です

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

メソッドを実装しますorientationChanged:

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

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

[[NSNotificationCenter defaultCenter] removeObserver:self];

ここにいくつかのリンクがあります

デバイスの向き - 自動回転?

向き変更通知

于 2011-06-18T13:53:14.300 に答える
1

まず 、mpviewController のサイズを変更する必要はないと思います。これは、単独でサイズが変更されるためです。- のみを設定する必要があります

2番

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
    }

}
于 2011-06-18T13:53:52.270 に答える
0

コーディングを変更する必要はありません..次のコーディングをアプリケーションに挿入するだけで、向きが自動的に検出されます...

UINavigationBar *bar = [self.navigationController ナビゲーションバー];
[bar setTintColor:[UIColor blackColor]]; NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"sharkdivertrailer" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] 保持];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.view.frame = CGRectMake(184, 200, 400, 300); [theMovie再生];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

于 2011-06-22T12:40:48.670 に答える