iPad 应用程序中的方向问题

发布于 2024-11-15 23:19:00 字数 1756 浏览 2 评论 0原文

我正在创建一个应用程序,在其中我需要播放由 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;
}

我不知道我错在哪里。请让我知道代码中的任何更改。从而得到正确的定位。

拉加兹·阿比

I am creating a application in which I can need to play a video which I do by mpmovieplayer controller .Now i nee to do this for both orientation .But the frame doesnt get set properly .

The code is as follws

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

I dont know where I am wrong.Please let me know for any chages to make in code. So as to get proper orientation.

Ragards Abhi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

决绝 2024-11-22 23:19:00

第一
我相信您不需要调整 mpviewController 的大小,因为它会自行调整大小。
您应该只设置 -

Second

在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
    }

}

First
I believe you don't need to resize the mpviewController as it will resize it self alone.
you should only set the -

Second

In the shouldAutorotateToInterfaceOrientation you only set the supported directions in shouldAutorotateToInterfaceOrientation.

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

If it dose not do it you change the view properties in -

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

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

}
眼藏柔 2024-11-22 23:19:00

您应该只在 shouldAutorotateToInterfaceOrientation: 方法中返回 YES 或 NO,框架调用它只是为了获取有关控制器中支持的方向的信息,请阅读苹果文档以获取相同的信息。

您需要注册方向更改通知

[[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];

以下是一些链接

设备方向 - 自动旋转?

方向更改通知

you should only return either YES or NO in shouldAutorotateToInterfaceOrientation: method, it's called by framework only to get the information about the supported orientation in your controller, Read the apple documentation for the same.

you need to register for the orientation change notifictaion

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

Implement your orientationChanged: method.

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

Not forget it to remove .

[[NSNotificationCenter defaultCenter] removeObserver:self];

Here are some link

Device orientation - autorotate?

Orientation Changed Notification

风吹雪碎 2024-11-22 23:19:00

无需更改任何编码..只需将以下编码插入应用程序,它将自动检测方向...

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] retain];      
        MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];     
        theMovie.view.frame = CGRectMake(184, 200, 400, 300);
        [theMovie play];  
        MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];       
        [self presentMoviePlayerViewControllerAnimated:moviePlayer];

No need to change any codings .. simple insert the following codings to the application , it will automatically detect the orientation...

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] retain];      
        MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];     
        theMovie.view.frame = CGRectMake(184, 200, 400, 300);
        [theMovie play];  
        MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];       
        [self presentMoviePlayerViewControllerAnimated:moviePlayer];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文