Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
asahiocean
SZRCAI
Commits
401f9251
Verified
Commit
401f9251
authored
Mar 10, 2021
by
asahiocean
🚀
Browse files
MKMapView addTarget for PinAnnotation
parent
b7e60caf
Changes
1
Hide whitespace changes
Inline
Side-by-side
SZRCAI/SZRCAI/Main code/Views/MapView/MapView.swift
View file @
401f9251
...
...
@@ -4,6 +4,18 @@ import MapKit
class
MapView
:
MKMapView
{
var
model
:
Model
=
.
shared
weak
var
lm
:
LocationManager
?
=
.
shared
@objc
fileprivate
func
appendPin
(
_
sender
:
UILongPressGestureRecognizer
)
{
guard
model
.
graphsBuilt
==
false
else
{
return
}
if
sender
.
state
!=
.
began
{
return
}
let
point
=
sender
.
location
(
in
:
self
)
let
coord
=
convert
(
point
,
toCoordinateFrom
:
self
)
let
annotation
=
PinAnnotation
(
t
:
"PIN"
,
sub
:
nil
,
c
:
coord
)
self
.
addAnnotation
(
annotation
)
}
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
...
...
@@ -21,6 +33,11 @@ class MapView: MKMapView {
isZoomEnabled
=
true
isScrollEnabled
=
true
let
longPress
=
UILongPressGestureRecognizer
()
longPress
.
minimumPressDuration
=
0.25
// in seconds
longPress
.
addTarget
(
self
,
action
:
#selector(
appendPin(_:)
)
)
addGestureRecognizer
(
longPress
)
register
(
PinMarkerView
.
self
,
forAnnotationViewWithReuseIdentifier
:
PinMarkerView
.
reuseId
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment