横向旋转后推动方向改变

时间:2014-02-09 18:30:05

标签: ios landscape uinavigation

我有仅限风景的应用。导航效果很好:当我推动一个新的视图时,它会从左到右滑动加载和显示。当它被卸载时,从右向左滑动。 但是,当我旋转设备时,事情会发生变化,现在推动从右到左。 要面对iOS 7中的一个错误,它不能处理旧式推送而不会避免出现滑动视图的奇怪延迟,我使用此代码

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

为什么?

2 个答案:

答案 0 :(得分:0)

当您将设备旋转180度时,您将从landscapeLeft转到landscapeRight ...左侧变为右侧,反之亦然。使用deviceRotation定义您的costom转换

e.g。第一个案例

transition.type = [UIDevice currentDevice]. orientation == UIDeviceRotationLandscapeLeft ? kCATransitionFromRight : kCATransitionFromLeft;

答案 1 :(得分:0)

这是正确的解决方案

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