ios - Modifying SwipeViewController Pod to run in a ContainerView -
so im using pod 'swipeviewcontroller' (https://github.com/fortmarek/swipeviewcontroller) gives me effect want problem runs main navigation controller , want work in container view because want use social app in profile menu twitter "my tweets", "likes", "repost"...
so example need this...
so explanation, make pod work need add line of code appdelegate
let pagecontroller = uipageviewcontroller(transitionstyle: .scroll, navigationorientation: .horizontal, options: nil) let navigationcontroller = yourviewcontrollername(rootviewcontroller: pagecontroller) self.window?.rootviewcontroller = navigationcontroller self.window?.makekeyandvisible()
wich creates new window swipecontroller, need way make work in view controller.
i did similar last night using tutorial here:
https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/
my associated code below. created iboutlet container view viewcontroller , code below adds appropriate view controller container view depending on setting of bool
called buttondefault
. make sure add child view container view , not main view view controller.
@iboutlet weak var containerview: uiview! // mark: container view // https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/ lazy var remoteviewcontroller: remoteviewcontroller = { // load storyboard let storyboard = uistoryboard(name: "mainstoryboard", bundle: nil) // instantiate view controller var viewcontroller = storyboard.instantiateviewcontroller(withidentifier: "remoteviewcontroller") as! remoteviewcontroller // add view controller child view controller self.add(aschildviewcontroller: viewcontroller) return viewcontroller }() lazy var gestureremoteviewcontroller: gestureremoteviewcontroller = { // load storyboard let storyboard = uistoryboard(name: "mainstoryboard", bundle: nil) // instantiate view controller var viewcontroller = storyboard.instantiateviewcontroller(withidentifier: "gestureremoteviewcontroller") as! gestureremoteviewcontroller // add view controller child view controller self.add(aschildviewcontroller: viewcontroller) return viewcontroller }() func add(aschildviewcontroller viewcontroller: uiviewcontroller) { // add child view controller addchildviewcontroller(viewcontroller) // add child view subview containerview.addsubview(viewcontroller.view) // configure child view viewcontroller.view.frame = containerview.bounds viewcontroller.view.autoresizingmask = [.flexiblewidth, .flexibleheight] // notify child view controller viewcontroller.didmove(toparentviewcontroller: self) } func remove(aschildviewcontroller viewcontroller: uiviewcontroller) { // notify child view controller viewcontroller.willmove(toparentviewcontroller: nil) // remove child view superview viewcontroller.view.removefromsuperview() // notify child view controller viewcontroller.removefromparentviewcontroller() } func updateview() { let settings = settings() if settings.buttondefault { remove(aschildviewcontroller: gestureremoteviewcontroller) add(aschildviewcontroller: remoteviewcontroller) } else { remove(aschildviewcontroller: remoteviewcontroller) add(aschildviewcontroller: gestureremoteviewcontroller) } }
once add call updateview()
in viewdidload
, time user selects new option view.
i hope helps.
Comments
Post a Comment