ios - Animate UIView with the default UINavigationInteractiveTransition interactive -
in app animate uiview
along default uinavigationinteractivetransition
. it's working charm when don't use interactive pangesture
.
is there way react current state of interactive animation via uiviewcontrollertransitioncoordinator
?
for implementation details see playground created:
//: playground - noun: place people can play import uikit import xcplayground class customnavigationcontroller: uinavigationcontroller { var customview: uiview! override func viewdidload() { customview = uiview(frame: cgrect(x: 0, y: 400, width: 300, height: 300)) customview.backgroundcolor = uicolor.redcolor() view.addsubview(customview) } } class customviewcontroller: uiviewcontroller { var dismissbutton: uibutton! dynamic func dismisscustomviewcontroller() { navigationcontroller?.popviewcontrolleranimated(true) } override func viewwilldisappear(animated: bool) { super.viewwilldisappear(animated) transitioncoordinator()?.animatealongsidetransition({ (context) in (self.navigationcontroller as? customnavigationcontroller)?.customview.backgroundcolor = uicolor.redcolor() }, completion: { (context) in // not implemented }) } override func viewwillappear(animated: bool) { super.viewwillappear(animated) transitioncoordinator()?.animatealongsidetransition({ (context) in (self.navigationcontroller as? customnavigationcontroller)?.customview.backgroundcolor = uicolor.yellowcolor() }, completion: { (context) in // not implemented }) } override func viewdidload() { title = "second controller" view.backgroundcolor = uicolor.purplecolor() dismissbutton = addbutton(withtitle: "dismiss controller", andselector: #selector(dismisscustomviewcontroller)) } } class firstviewcontroller: uiviewcontroller { var pushbutton: uibutton! dynamic func pushcustomviewcontroller() { let customviewcontrolelr = customviewcontroller() navigationcontroller?.pushviewcontroller(customviewcontrolelr, animated: true) } override func viewdidload() { title = "firstcontroller" view.backgroundcolor = uicolor.whitecolor() pushbutton = addbutton(withtitle: "push controller", andselector: #selector(pushcustomviewcontroller)) } } extension uiviewcontroller { func addbutton(withtitle title: string, andselector selector: selector) -> uibutton { let button = uibutton(type: .custom) button.settitle(title, forstate: .normal) button.settitlecolor(uicolor.blackcolor(), forstate: .normal) button.translatesautoresizingmaskintoconstraints = false button.addtarget(self, action: selector, forcontrolevents: .touchupinside) view.addsubview(button) let views = ["button" : button] let constraintsh = nslayoutconstraint.constraintswithvisualformat("h:|-20-[button]-20-|", options: [], metrics: nil, views: views) let constraintsv = nslayoutconstraint.constraintswithvisualformat("v:|-100-[button(60)]", options: [], metrics: nil, views: views) view.addconstraints(constraintsh) view.addconstraints(constraintsv) return button } } let firstviewcontroller = firstviewcontroller() let navcontroller = customnavigationcontroller(rootviewcontroller: firstviewcontroller) xcplaygroundpage.currentpage.liveview = navcontroller.view
Comments
Post a Comment