ios - ViewController as Overlay on MapView in Swift (like Google Maps Application User Interface) -


i'm building small app swift want achieve following: - mapview several annotations - click on 1 of annotations shows details in overlay moving in bottom , fill approx. half of screen - upper half of display still shows mapview. click on map closes details

now i've read lot different possibilities. first i've tried using containerview this:

enter image description here

@iboutlet weak var detailscontaineryposition: nslayoutconstraint!  func mapview(mapview: mkmapview!, didselectannotationview view: mkannotationview!) {     uiview.animatewithduration(0.3, delay: 0.0, options: uiviewanimationoptions.curveeaseout, animations: {         self. detailscontaineryposition.constant = 0         self.view.layoutifneeded()          }, completion: nil) } 

the problem was, viewdidload() method fired once , wanted use build details page after passing data controller class.

so next i've played around custom segue , cam this:

class detailssegue: uistoryboardsegue {     override func perform() {         // assign source , destination views local variables.         var mapview = self.sourceviewcontroller.view uiview!         var detailsview = self.destinationviewcontroller.view uiview!          // screen width , height.         let screenwidth = uiscreen.mainscreen().bounds.size.width         let screenheight = uiscreen.mainscreen().bounds.size.height          // specify initial position of destination view.         detailsview.frame = cgrectmake(0.0, screenheight, screenwidth, 140)          // access app's key window , insert destination view above current (source) one.         let window = uiapplication.sharedapplication().keywindow         window?.insertsubview(detailsview, abovesubview: mapview)          // animate transition.         uiview.animatewithduration(0.4, animations: { () -> void in             detailsview.frame = cgrectoffset(detailsview.frame, 0.0, -140)         }, completion: nil)     } } 

this seems better solution because send data new controller within prepareforsegue() function , viewdidload() method fired every time segue initiated i'm struggling: - everytime annotation clicked , segue called, new view inserted. if 1 detail view visible, update 1 - can't find way unwind segue when diddeselectannotationview called mapview.

but perhaps here has better way achieve ui this.

i've managed wanted manually adding viewcontroller , view this:

let detailswidth: cgfloat = view.bounds.width let detailsheight: cgfloat = 150 let detailsviewframe: cgrect = cgrectmake(0, view.bounds.height, detailswidth, detailsheight)  detailscontroller = storyboard?.instantiateviewcontrollerwithidentifier("details") as! detailsviewcontroller detailscontroller.descriptiontext = "i'm text passed mainviewcontroller"  self.addchildviewcontroller(detailscontroller) detailscontroller.view.frame = detailsviewframe view.addsubview(detailscontroller.view) detailscontroller.didmovetoparentviewcontroller(self) 

and when dismissing details, remove controller this:

self.detailscontroller.removefromparentviewcontroller() 

i created small sample demonstrate solution: https://github.com/flavordaaave/ios-container-view-overlay


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -