Подтвердить что ты не робот

Невозможно обрабатывать ориентацию в iOS 6?

Я использую

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

делегат изменить кадр моего представления на основе типа ориентации

i.e.,

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

Как обрабатывать ту же ситуацию в iOS 6 как

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

устарел в iOS6.

Я использую следующий делегат для установки всех ориентаций.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationAllMask;
}

Но,

-(BOOL)shouldAutoRotate
{
    return YES;

}

не вызывается. Как справиться с этой ситуацией?

enter image description here

4b9b3361

Ответ 1

В AppDelegate я добавил объект ViewController в окно как

[self.window addSubView:viewControllerObj]

Проблема была в вышеупомянутой строке. Ориентация будет корректно работать с приведенной выше строкой в ​​iOS 5, но в iOS, чтобы ориентация на правильную работу изменила указанную выше строку с помощью

[self.window setRootViewController:viewControllerObj]

Затем приложение поворачивается при изменении ориентации.

Ответ 2

Удостоверьтесь, что настройки в проекте и цели позволяют определять ориентацию для каждого типа устройства.

Кроме того, код, который у вас есть в shouldAutorotateToInterfaceOrientation:, можно поместить в viewDidLayoutSubviews.

Ответ 3

Помните, что в iOS 6 обработка вращения берет на себя заботу о родителях. Меньшая ответственность перед контроллерами просмотра детей. Но более раздражающим для нас, который кодирует все без конструктора интерфейса.

Ответ 4

Убедитесь, что включена вся ориентация. enter image description here

Ответ 5

Обработка проблемы ориентации UINavigation в iOS 6

1 Создайте класс категории UINavigation + Rotation

2 помещают ниже методы в UINavigation + Rotation.m class

-(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];
}

Ответ 6

Этот метод отлично работает для IOS 6 и более старых версий

-(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;

}

Ответ 7

Используйте willAnimateRotationToInterfaceOrientation в iOS6.