Nie możesz obsłużyć orientacji w systemie iOS 6?

Używam

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

Delegat do zmiany ramki mojego widoku na podstawie typu orientacji

Tzn.,

if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
    self.view.frame=CGRectMake(0,0,500,300);
}
else
{
    self.view.frame=CGRectMake(0,0,300,400);
}

Jak poradzić sobie z tą samą sytuacją w iOS 6 co

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

Został wycofany z iOS6.

Używam poniższego delegata, aby ustawić wszystkie orientacje.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationAllMask;
}

Ale,

-(BOOL)shouldAutoRotate
{
    return YES;

}

Nie jest wywoływany. Jak poradzić sobie z tą sytuacją?

Tutaj wpisz opis obrazka

Author: Bharath, 2012-09-20

7 answers

W AppDelegate dodałem obiekt ViewController Do window jako

[self.window addSubView:viewControllerObj]

Problem był z powyższą linią. Orientacja będzie działać poprawnie z powyższą linią w iOS 5, ale w iOS, aby orientacja działała poprawnie, Zmień powyższą linię za pomocą

[self.window setRootViewController:viewControllerObj]

Następnie aplikacja obraca się, gdy zmienia się orientacja.

 46
Author: Bharath,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-21 10:55:06

Upewnij się, że ustawienia w projekcie i celu pozwalają na orientację dla każdego typu urządzenia.

Również kod, który masz w shouldAutorotateToInterfaceOrientation: możesz umieścić w viewDidLayoutSubviews.

 3
Author: Leo Natan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-20 19:39:17

Pamiętaj, że w iOS 6 obsługa rotacji odbywa się w widoku rodziców. Mniejsza responsywność dla kontrolerów childs viewcontrollers. Ale bardziej irytujące dla nas, że kod wszystko bez konstruktora interfejsu.

 1
Author: lagos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-21 10:17:37

Upewnij się, że cała Twoja orientacja jest włączona.Tutaj wpisz opis obrazka

 0
Author: Gurumoorthy Arumugam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-22 11:49:06

Obsługa problemu z orientacją UINavigation w iOS 6

1 Utwórz klasę kategorii UINavigation+Rotation

2 Umieść poniżej metody w UINavigation+Rotation.Klasa m

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject]supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([self.viewControllers count] == 0) {
        return UIInterfaceOrientationPortrait;
    }
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
 0
Author: Ricard Pérez del Campo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-07 08:48:44

Ta metoda działa dobrze dla IOS 6 i starszych wersji


-(BOOL)rotationChanged:(UIInterfaceOrientation)interfaceOrientation {
    NSInteger orientation = [[UIDevice currentDevice] orientation];
    UIWindow *_window = [[[UIApplication sharedApplication] delegate] window];
    if ([PGPlatformUtils GetCurrentPlatform]==PGPlatformEnum_iPhone) {
        switch (orientation) {
            case 1:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];

                [UIView commitAnimations];
                break;
            case 2:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];

                [UIView commitAnimations];
                break;
            case 3:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];

                [UIView commitAnimations];
                break;
            case 4:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];

                [UIView commitAnimations];
                break;
            case 5:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIPrintInfoOrientationLandscape animated:YES];

                [UIView commitAnimations];
                break;


            default:
                break;
        }
    }
    else{
        switch (orientation) {
            case 1:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
                NSLog(@"*** 1 Orientation Call 0");

                [UIView commitAnimations];
                break;
            case 2:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:YES];
                NSLog(@"*** 1 Orientation Call M_PI");
                [UIView commitAnimations];
                break;
            case 3:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
                NSLog(@"*** 1 Orientation Call M_PI/2");
                [UIView commitAnimations];
                break;
            case 4:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
                NSLog(@"*** 1 Orientation Call - M_PI/2");
                [UIView commitAnimations];
                break;
            case 5:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIPrintInfoOrientationLandscape animated:YES];
                NSLog(@"*** 1 Orientation Call 0");
                [UIView commitAnimations];
                break;

            default:
                break;
        }
    }
    return YES;

}
 0
Author: eranda.del,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-07 09:01:33

Użyj willAnimateRotationToInterfaceOrientation w iOS6.

 0
Author: Andrew,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-05 07:49:47