Невозможно определить портретную ориентацию на iPhone - PullRequest
2 голосов
/ 02 июля 2011

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
                   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
                   interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
                   interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


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

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

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

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

1 Ответ

1 голос
/ 02 июля 2011

Вы можете немного упростить этот код, это может помочь сузить его.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES; // Return YES is the same as entering all interfaces.
}


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

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {

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

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    NSLog(@"dismissing chart");
    [self.parentViewController dismissModalViewControllerAnimated:NO];
    // self.parentViewController seems like a call FROM the modalViewController. 
    // This should be moved to the modalViewControllers implementation
}
}

Просто глядя на это, я думаю, что вам нужно отключить контроллер модального представления внутри модального представления, а не внутри родительского представления. Таким образом, вы должны использовать альбомную версию внутри основного контроллера, а затем добавить «willAnimateRotation ...» к модальному контроллеру для обработки портретного вращения.

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