iPad应用程序中的定向问题

| 我正在创建一个应用程序,在该应用程序中,我需要播放由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;
}
我不知道我在哪里错。请让我知道代码中有什么麻烦。以便获得正确的方向。 拉加德·阿比(Ragards Abhi)     
已邀请:
        第一 我相信您不需要调整mpviewController的大小,因为它可以自行调整大小。 您只应设置- 第二 在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
    }

}
    
        您只应在
shouldAutorotateToInterfaceOrientation:
方法中返回YES或NO,它仅被框架调用以获取有关控制器中支持的方向的信息,请阅读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];
这是一些链接 设备方向-自动旋转? 方向更改通知     
        无需更改任何编码..只需将以下编码插入应用程序,它将自动检测方向... UINavigationBar * bar = [self.navigationController navigationBar]; [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);         [电影播放];         MPMoviePlayerViewController * moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];         [self presentMoviePlayerViewControllerAnimated:moviePlayer];     

要回复问题请先登录注册