ios - MapView doesn't work anymore if I add a GestureRecognizer -
i'm trying add pin @ map when user longpress (with uilongpressgesturerecognizer), doesn't work. however, bigger problem is: map isn't displayed anymore. why map has disappeared?
you find project-file here
---------------------------viewcontroller.swift--------------------------------
{ import uikit import mapkit class viewcontroller: uiviewcontroller, mkmapviewdelegate { @iboutlet var themapview: mkmapview! @iboutlet var thetextfield: uitextfield! @iboutlet var thelabel: uilabel! @ibaction func thebutton(sender: uibutton) { thelabel.text = "swift-app schreibt \(thetextfield.text)" thetextfield.resignfirstresponder() } override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. // position var latitude:cllocationdegrees = 48.399193 var longitude:cllocationdegrees = 9.993341 // zoomfaktor var latdelta:cllocationdegrees = 0.01 var longdelta:cllocationdegrees = 0.01 // var thespan:mkcoordinatespan = mkcoordinatespanmake(latdelta,longdelta) // koordinaten der kirche var churchlocation:cllocationcoordinate2d = cllocationcoordinate2dmake(latitude, longitude) // zentrum und kartenausschnitt var theregion:mkcoordinateregion = mkcoordinateregionmake(churchlocation, thespan) // longtap definieren let longpress = uilongpressgesturerecognizer(target: themapview, action: "actionpin:") longpress.minimumpressduration = 1.0 longpress.numberoftouchesrequired = 1 longpress.allowablemovement = 100 themapview.addgesturerecognizer(longpress) // karte anzeigen themapview.setregion(theregion,animated:false) // pin setzen var theulmminsterannotation = mkpointannotation() theulmminsterannotation.coordinate = churchlocation theulmminsterannotation.title = "ulmer münster" theulmminsterannotation.subtitle = " untertitel" themapview.addannotation(theulmminsterannotation) } func actionpin(gesturerecognizer:uigesturerecognizer) { var touchpoint = gesturerecognizer.locationinview(self.themapview) var newcoord:cllocationcoordinate2d=themapview.convertpoint(touchpoint, tocoordinatefromview: self.themapview) var newannotation = mkpointannotation() newannotation.coordinate = newcoord newannotation.title = "fingertipp" newannotation.subtitle = "untertitel" themapview.addannotation(newannotation) } }}
because map size it's {0,0} , not using constrain.
check here project minor update https://dl.dropboxusercontent.com/u/19438780/test1-v2.zip
Comments
Post a Comment