ios - Wait with execution of viewWillDisappear until custom animation has completed? -
i'd perform animation when user taps on button segue root view controller. animation highlight changes user made in detail view controller.
i tried this. animation works (and not essential question, left in illustrate i'm doing.) problem segueing happens fast , can't see animation.
how can wait
execution of viewwilldisappear until animation has completed?
override func viewwilldisappear(animated: bool) { // ... // animate if text changes. reminderafterrulesrun custom data structure. remindernametextinput outlet label if remindernametextinput.text != reminderafterrulesrun.title { let originalremindernametextinputcolor = self.remindernametextinput.textcolor // animate removing of "all" , replacing commonly used list. uiview.animatewithduration(0.3, delay: 0, options: .autoreverse, animations: { // fade out self.remindernametextinput.textcolor = uicolor.redcolor() self.remindernametextinput.text = reminderafterrulesrun.title self.remindernametextinput.alpha = 0.0 }, completion: { (finished: bool) -> void in // once label invisible, set text , fade in uiview.animatewithduration(0.3, delay: 0, options: .autoreverse, animations: { // self.remindernametextinput.selectedsegmentindex = self.tosegmentedcontrolvalue(reminderafterrulesrun.remindernametextinput)! self.remindernametextinput.text = reminderafterrulesrun.title self.remindernametextinput.textcolor = originalremindernametextinputcolor self.remindernametextinput.alpha = 1.0 }, completion: nil) }) } }
looks you'll want use view controller transition api. @ high level need implement uinavigationcontrollerdelegate
protocol methods in view controller. when set view controller delegate of nav controller , transition happen, method called. here can check , see view controllers involved in interaction , direction transition going (push or pop). info can provide appropriate animator.
- (id<uiviewcontrolleranimatedtransitioning>) navigationcontroller:(uinavigationcontroller *)navigationcontroller animationcontrollerforoperation:(uinavigationcontrolleroperation)operation fromviewcontroller:(uiviewcontroller*)fromvc toviewcontroller:(uiviewcontroller*)tovc { if (operation == uinavigationcontrolleroperationpush) { return self.animator; } return nil; }
the "animator" nsobject subclass implements uiviewcontrolleranimatedtransitioning
protocol. protocol has methods ask time of transition
- (nstimeinterval)transitionduration:(id <uiviewcontrollercontexttransitioning>)transitioncontext { return 0.25; }
and call implementing transition:
- (void)animatetransition: (id<uiviewcontrollercontexttransitioning>)transitioncontext { uiviewcontroller* toviewcontroller = [transitioncontext viewcontrollerforkey:uitransitioncontexttoviewcontrollerkey]; uiviewcontroller* fromviewcontroller = [transitioncontext viewcontrollerforkey:uitransitioncontextfromviewcontrollerkey]; [[transitioncontext containerview] addsubview:toviewcontroller.view]; toviewcontroller.view.alpha = 0; [uiview animatewithduration:[self transitionduration:transitioncontext] animations:^{ fromviewcontroller.view.transform = cgaffinetransformmakescale(0.1, 0.1); toviewcontroller.view.alpha = 1; } completion:^(bool finished) { fromviewcontroller.view.transform = cgaffinetransformidentity; [transitioncontext completetransition:![transitioncontext transitionwascancelled]]; }]; }
Comments
Post a Comment