2012-05-11 7 views
7

Ja, ich habe schon eine Antwort gesucht. Keine der Lösungen funktioniert, außer einer, die keine Option für einen Überblendungsübergang bietet, nur Flip oder Curl.popViewControllerAnimated: Benutzerdefinierte Übergangsanimation?

So:

methodname 
    configure animation 
    [self.navigationController popViewControllerAnimated:NO]; 

Egal, welche Vielzahl von Übergangsanimation Config ich versuche, ist nichts sichtbar anders als nur den typischen Single-Line-Pop mit. Wenn ich es in …Animated:YES]; ändere, bekomme ich die Standard-Pop-Animation, vielleicht mit etwas Seltsames passiert aus der defekten Konfig.

Also meine Frage ist: Wie kann ich mit einem pop tun, wenn nicht CrossDissolve, dann zumindest etwas, das gleich aussieht? Ist das mit einem Navigationscontroller überhaupt möglich?

Die Verwendung modaler Ansichten würde die Standardanimation haben, die ich möchte, und ich könnte den Ansichtsstapel leicht genug verwalten, aber das möchte ich nicht tun.

Antwort

23

Für diese Art von Übergang würde ich wirklich einen Modal View Controller empfehlen, so wurde das System entworfen.

Aber wenn Sie darauf bestehen, den Navigationscontroller zu verwenden, gibt es einen Weg, obwohl etwas hässlich.

[CATransaction begin]; 
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 

CATransition *transition = [CATransition animation]; 
[transition setType:kCATransitionFade]; 
[self.navigationController.view.layer addAnimation:transition forKey:@"someAnimation"]; 

[self.navigationController popViewControllerAnimated:YES]; 
[CATransaction commit]; 

Die CATransaction deaktiviert alle Standardanimationen. Die CATransition fügt einen Fade-Übergang zur Ebene der Navigationssteuereinheit hinzu, wenn Ansichten vertauscht werden (in diesem Fall wird die ViewController-Ansicht entfernt, die geöffnet wird).

+2

Absolut perfekt. – Thromordyn

+1

In iOS 7 finde ich, dass ich NO zu popViewControllerAnimated anstatt YES übergeben muss, aber ansonsten funktioniert das gut. – EricS

2

In iOS 7 oben, können Sie in UIViewControllerAnimatedTransitioning für präsentiert View-Controller suchen möchten, oder UINavigationControllerDelegate Methode:

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC 

Ich habe einige sample code from another question für weitere Informationen.

0

Joris Kluivers Antwort in Swift 3:

CATransaction.begin() 
CATransaction.setDisableActions(true) 

let animation = CATransition() 
animation.type = kCATransitionFade 
self.navigationController?.view.layer.add(animation, forKey: "someAnimation") 
_ = self.navigationController?.popViewController(animated: false) 

CATransaction.commit() 
Verwandte Themen