0

I have landscape-only app. And navigation works well: when I push a new View, it gets loaded and shown by sliding from left to right. When it gets unloaded, the sliding from right to left. But, when I rotate the device, things change and the pushing is now from right to left. To face a bug in iOS 7 which does not handle old style pushing without avoiding strange lazy appearing of the sliding views, I use this code

- (void)pushViewControllerRetro:(UIViewController *)viewController {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromBottom;
    [self.view.layer addAnimation:transition forKey:nil];

    [self pushViewController:viewController animated:NO];
}

- (void)popViewControllerRetro {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;
    [self.view.layer addAnimation:transition forKey:nil];

    [self popViewControllerAnimated:NO];
}

Why?

gdm
  • 7,647
  • 3
  • 41
  • 71

2 Answers2

0

when you rotate the device 180 degrees, you go from landscapeLeft to landscapeRight ... left becomes right and vice versa. use the deviceRotation to define your costom transitions

e.g. first case

transition.type = [UIDevice currentDevice]. orientation == UIDeviceRotationLandscapeLeft ? kCATransitionFromRight : kCATransitionFromLeft;
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • OK, sorry I miscopied the code. see my edit. Your solution (u meant UIDeviceOrientationLandscapeLeft, didn't u) disables the animation of pushing... – gdm Feb 09 '14 at 19:15
0

This is the right solution

- (void)pushViewControllerRetro:(UIViewController *)viewController {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;


     transition.subtype = [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight ?kCATransitionFromBottom : kCATransitionFromTop;
    [self.view.layer addAnimation:transition forKey:nil];

    [self pushViewController:viewController animated:NO];

}

- (void)popViewControllerRetro {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight ?kCATransitionFromTop : kCATransitionFromBottom;

    [self.view.layer addAnimation:transition forKey:nil];

    [self popViewControllerAnimated:NO];
}
gdm
  • 7,647
  • 3
  • 41
  • 71