Проблема с ориентацией в приложении для iPad - PullRequest
1 голос
/ 18 июня 2011

Я создаю приложение, в котором мне может понадобиться воспроизвести видео, которое я делаю с помощью контроллера 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;
}

Я не знаю, где я ошибаюсь. Пожалуйста, дайте мне знать о любых изменениях в коде. Чтобы получить правильную ориентацию.

Рагардс Абхи

Ответы [ 3 ]

1 голос
/ 18 июня 2011

Первый Я считаю, что вам не нужно изменять размер 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
    }

}
1 голос
/ 18 июня 2011

вы должны возвращать только ДА или НЕТ в методе 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];

Вот какая-то ссылка

Ориентация устройства - автоматический поворот?

Уведомление об изменении ориентации

0 голосов
/ 22 июня 2011

Нет необходимости менять какие-либо кодировки .. просто вставьте в приложение следующие кодировки, оно автоматически определит ориентацию ...

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); [theMiepe play];
MPMoviePlayerViewController * moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL: movieURL];
[selfsentMoviePlayerViewControllerAnimated: moviePlayer];

...