ios - Specify direction of "show" (push) segue -
is there simple way specify direction (from left, right, top, or bottom) of "show" segue (previously called "push" segue)?
the default "show" segue goes left right, go bottom top.
i don't believe there built in method achieve that, use custom transitions, introduced in ios7. there plenty of great tutorials out there, i've added links below , sample code demonstrating how slide new view controller down top.
sites check out:
introduction custom view controller transitions , animations
raywenderlich: how make view controller transition animation in ping app
(note: way uiviewcontroller's view accessed in third , fourth tutorials outdated. instead of toviewcontroller.view should use transitioncontext.viewforkey(uitransitioncontexttoviewkey))
an example:
firstly, you're going need set storyboard, i'm going assume you've done.
secondly, need nsobject subclass conforms uiviewcontrolleranimatedtransitioning. used control transition 1 view controller next.
class transitionmanager : nsobject, uiviewcontrolleranimatedtransitioning { let animationduration = 0.5 func transitionduration(transitioncontext: uiviewcontrollercontexttransitioning) -> nstimeinterval { return animationduration } func animatetransition(transitioncontext: uiviewcontrollercontexttransitioning) { let containerview = transitioncontext.containerview() let toview = transitioncontext.viewforkey(uitransitioncontexttoviewkey)! containerview.addsubview(toview) let finalframe = containerview.bounds let initalframe = cgrect(x: 0, y: -finalframe.height, width: finalframe.width, height: finalframe.height) toview.frame = initalframe uiview.animatewithduration(animationduration, animations: { toview.frame = finalframe }, completion: { _ in transitioncontext.completetransition(true) }) } } as described in raywenderlich: how make view controller transition animation in ping app tutorial, you'll need setup uinavigationcontroller's delegate. following navigationcontrollerdelegate class used return instance of transitionmanager when push segue being conducted:
class navigationcontrollerdelegate: nsobject, uinavigationcontrollerdelegate { let transitionmanager = transitionmanager() func navigationcontroller(navigationcontroller: uinavigationcontroller, animationcontrollerforoperation operation: uinavigationcontrolleroperation, fromviewcontroller fromvc: uiviewcontroller, toviewcontroller tovc: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? { if operation == .push { return transitionmanager } return nil } } and should it! expand on i'd recommend take @ interactive transitions.
Comments
Post a Comment