2014-02-09 85 views
0

我有橫向專用的應用程序。導航效果很好:當我推新視圖時,它會從左向右滑動並加載顯示。當它被卸載時,從右向左滑動。 但是,當我旋轉設備時,事情會改變,推動現在從右向左。 面對的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]; 
} 

爲什麼?

+0

你的意思是,如果你旋轉180度? –

+0

是的,我的意思是 – giuseppe

回答

0

當您將設備旋轉180度時,您將從landscapeLeft到landscapeRight ... left變爲正確,反之亦然。使用deviceRotation來定義你的德,崔根源過渡

例如第一種情況

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

好的,對不起,我錯誤的代碼。看我的編輯。你的解決方案(你的意思是UIDeviceOrientationLandscapeLeft,沒有)禁用推動動畫... – giuseppe

+0

你取消了轉換並在每次旋轉後創建... –

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