mkmapview - Swift - How to ask UIGestureRecognizer function to return value -
i ask function annotation return coordinate (cllocationcoordinate2d) other function use, here's partial code:
// ulmap mapview. override func viewdidload() { var longpressgr = uilongpressgesturerecognizer(target: self, action: "annotation:") longpressgr.minimumpressduration = 1 uimap.addgesturerecognizer(longpressgr) } func annotation(gesture: uigesturerecognizer){ //coordinate var touchpoint = gesture.locationinview(self.uimap) var coordinate = uimap.convertpoint(touchpoint, tocoordinatefromview: self.uimap) }
i tried one, doesn't work:
func annotation(gesture: uigesturerecognizer) -> cllocationcoordinate2d{ //coordinate var touchpoint = gesture.locationinview(self.uimap) var coordinate = uimap.convertpoint(touchpoint, tocoordinatefromview: self.uimap) return coordinate }
is there way this? in advance.
things gesture recognizer calls can't return because aren't 1 calling them. getting called system, return value propagate through code don't have access to. should create class level variable coordinate , set that.
so instead of saying var coordinate = uimap.convertpoint(touchpoint, tocoordinatefromview: self.uimap)
you declare
var coordinate:cllocationcoordinate2d
at class scope, , in function
coordinate = uimap.convertpoint(touchpoint, tocoordinatefromview: self.uimap)
then coordinate set coordinate. can add them array if need keep track of more one.
Comments
Post a Comment