UIViewController застревает в горизонтальной ориентации после поворота портрета - PullRequest
0 голосов
/ 05 июля 2011

View Controller A отображает View Controller B в горизонтальной ориентации

#pragma mark Rotation Delegate Methods
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return YES;
}

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

    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        [landscapeChartViewController.chartImageView reloadWithUrl:
            [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]];

        NSLog(@"showing chart");
        [self presentModalViewController:landscapeChartViewController animated:NO];
    }    
}

Это прекрасно работает.Контроллер вида B отображается в горизонтальной ориентации.Вот реализация View Controller B:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

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

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        NSLog(@"dismissing chart");
        [self.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

Проблема в том, что когда я возвращаюсь в портретную ориентацию, чтобы показать View Controller A, View Controller A застревает в горизонтальной ориентации.Как я могу это исправить?

Ответы [ 5 ]

0 голосов
/ 04 сентября 2013

Я всегда пишу свою логику ориентации в didRotateFromInterfaceOrientation.Вот часть моего кода, он отлично работает ....

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
         [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)];
         UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

        if (orientation == UIDeviceOrientationLandscapeLeft || orientation ==    UIDeviceOrientationLandscapeRight){

            [connectCoverLockUnlockSwitch setFrame:CGRectMake(400,6,51,31)];
            [self.tableView reloadData];
        }
        else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortrait){

        [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)];

}}

    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)     {
          UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];        

       if (orientation == UIDeviceOrientationUnknown || orientation ==   UIDeviceOrientationFaceUp) {

//return;

  }
         if (orientation == UIDeviceOrientationLandscapeLeft || orientation ==   UIDeviceOrientationLandscapeRight) {
              [connectCoverLockUnlockSwitch setFrame:CGRectMake(570,6,51,31)];

               [self.tableView reloadData];
       }

  else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation ==   UIDeviceOrientationPortrait)
       {
            [connectCoverLockUnlockSwitch setFrame:CGRectMake(330,6,51,31)];
            [self.tableView reloadData];

          }
          }
0 голосов
/ 06 июля 2011

Реализовали ли вы функцию willRotateToInterfaceOrientation?Также попробуйте использовать Центр уведомлений, чтобы уведомить родительский контроллер представления о том, что ваш модальный контроллер представления повернут, а затем просто [self dismissModalViewControllerAnimated: YES]

0 голосов
/ 05 июля 2011

Один из вариантов - переместить код с willAnimateRotationToInterfaceOrientation: на didRotateFromInterfaceOrientation: и использовать self.interfaceOrientation вместо toInterfaceOrientation.

0 голосов
/ 05 июля 2011

View Controller B отображается в горизонтальной ориентации.Вот реализация View Controller B:

  • (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {

    // Возвращаем YES для поддерживаемых ориентаций, возвращаем YES;

}

- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) длительность {

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    NSLog(@"dismissing chart");
    [self dismissModalViewControllerAnimated:NO];
}

}

0 голосов
/ 05 июля 2011

РЕДАКТИРОВАТЬ: после прочтения вашего комментария я предлагаю попробовать использовать willRotateToInterfaceOrientation:duration: вместо willAnimateRotationToInterfaceOrientation, например:

контроллер A:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
   if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
     [landscapeChartViewController.chartImageView reloadWithUrl:
        [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]];

     NSLog(@"showing chart");
     [self presentModalViewController:landscapeChartViewController animated:NO];
   }    
}

контроллер B:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
      NSLog(@"dismissing chart");
      [self.parentViewController dismissModalViewControllerAnimated:NO];
  }
}

Я делаю более или менее то же самое в моем проекте, только между двумя немодальными видами.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...