2015-07-01 3 views
11

Hier entlassen mein Code verwendet, um eine navigationViewController vorstellen:CATransition falsch auf Orientierungsänderung zu arbeiten, bevor ein NavigationViewController

-(IBAction)showFilterView:(id)sender { 

    FilterViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"FilterViewController"]; 
    UINavigationController *nvc=[[UINavigationController alloc] initWithRootViewController:vc]; 


    CATransition *transition = [CATransition animation]; 
    transition.duration = 0.35; 
    transition.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionMoveIn; 
    transition.subtype = kCATransitionFromLeft; 

    UIView *containerView = self.view.window; 
    [containerView.layer addAnimation:transition forKey:nil]; 
    [self.tabBarController presentViewController:nvc animated:NO completion:nil]; 

} 

Und hier ist mein Code

-(IBAction)back:(id)sender { 


    CATransition *transition = [CATransition animation]; 
    transition.duration = 0.35; 
    transition.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionMoveIn; 
    transition.subtype = kCATransitionFromRight; 
    UIView *containerView = self.view.window; 
    [containerView.layer addAnimation:transition forKey:nil]; 
    [[self.navigationController presentingViewController] dismissViewControllerAnimated:NO completion:nil]; 
} 

Situation 1 --- Arbeiten zu entlassen auch im Landschaftsmodus

Situation 2 --- Arbeiten auch im Portrait-Modus

Situation 3 --- Im Hochformatmodus zeigen und im Querformat ablehnen funktioniert nicht richtig (zusätzliche Animation vor Anzeige der korrekten Ansicht)

Situation 4 --- Im Querformat und im Hochformat nicht korrekt arbeiten (zusätzliche Animation, bevor die korrekte Ansicht angezeigt wird)

+0

Ist es https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html helfen – aProgrammer

+0

ich Ihren Code auf dem iPad-Projekt getestet und es funktioniert mit einer Animation in Ordnung, außer, dass ich getestet mit presenting from self nicht von einem tabBarController: '[self presentViewController: nvc animiert: NO completion: nil]' – Idali

+0

In UIView * containerView = self.view.window weisen Sie das ganze Fenster (UIWindow *) einer UIView * zu. Sollten Sie die Ansichtsebene nicht animieren, nicht das Fenster? –

Antwort

0

Die UIWindow-Ebene weist seltsame Rotationseigenschaften auf und es ist nicht garantiert, dass die von Ihnen ausgeführten Animationen die Ausrichtung korrekt erkennen (und variieren je nach iOS-Version). Der einfachste Weg, um das zu tun, was Sie versuchen, ist eine benutzerdefinierte Präsentationsanimation. This is a good writeup wie es geht.

Verwandte Themen