swift - UINavigationControllerDelegate methods, custom transitioning using navigation controller in ios 8 -


i trying create custom transition when popping or pushing ti navigation controller. have created transitionmanager class conforms uinavigationcontrollerdelegate. have created object of transitionmanager , added transitioningdelegate navigationcontroller.

the push animation runs great when try pop previous viewcontroller see black screen.

i've ran through numerous other posts make work , tried @ hand still doesn't show previous viewcontroller when pop.

the code transitionmanager here:

import uikit

class brtransitionmanager: nsobject, uinavigationcontrollerdelegate, uiviewcontrolleranimatedtransitioning {

private var presenting = true  func navigationcontroller(navigationcontroller: uinavigationcontroller, animationcontrollerforoperation operation: uinavigationcontrolleroperation, fromviewcontroller fromvc: uiviewcontroller, toviewcontroller tovc: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? {      if  operation == uinavigationcontrolleroperation.push{         self.presenting = true     } else if operation == uinavigationcontrolleroperation.pop{         self.presenting = false     }      return self }  func animatetransition(transitioncontext: uiviewcontrollercontexttransitioning) {     let container = transitioncontext.containerview()     let fromview = transitioncontext.viewforkey(uitransitioncontextfromviewkey)!     let toview = transitioncontext.viewforkey(uitransitioncontexttoviewkey)!      // set 2d transforms we'll use in animation     let offscreenright = cgaffinetransformmaketranslation(container.frame.width, 0)     let offscreenleft = cgaffinetransformmaketranslation(-container.frame.width, 0)      // prepare toview animation     if  (self.presenting == true){         // add both views our view controller         container.addsubview(toview)         //        container.addsubview(fromview)          toview.transform = offscreenright     } else {         toview.transform = offscreenleft     }      let duration = self.transitionduration(transitioncontext)     uiview.animatewithduration(duration, delay: 0.0, usingspringwithdamping: 0.5, initialspringvelocity: 0.8, options: nil, animations: {          if  (self.presenting == true){             fromview.transform = offscreenleft         } else {             fromview.transform = offscreenright         }          toview.transform = cgaffinetransformidentity          }, completion: { finished in              transitioncontext.completetransition(true)     }) }  func transitionduration(transitioncontext: uiviewcontrollercontexttransitioning) -> nstimeinterval {     return 0.8 }    } 

can please me solve issue?

the uinavigationcontroller maintains weak reference delegate. if there no strong reference uinavigationcontrollerdelegate object deallocated once transition complete.

you can set delegate object in storyboard editor. add object dragging object palette onto navigation controller scene, between first responder , exit icons. set class of delegate object. make module current application module. control-drag navigation controller icon object icon , choose "delegate" popup menu.

this seems maintain strong reference delegate object. delegate object available invoke unwind transition. don't need create object or set delegate reference.

i found technique in blog post scott james remnant.

scott james remnant - custom ios segues, transitions, , animations - right way


Comments