我想编写一个APP,用户可以通过按地图在地图上删除图钉。引脚掉线后,我想将引脚保存到数据库中。我不关心哪一个可能与Realm
或CoreData
。
答案 0 :(得分:0)
RTFM
没有任何代码或任何问题,无法真正帮助您。
一些可能有用的链接: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/index.html https://developer.apple.com/reference/corelocation https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009497
在你尝试之后回来;)
编辑:
您在viewDidLoad
方法中定义了一个手势识别器,将其直接放在您的控制器中,这样可以删除一些错误:
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Create a gesture recognizer for long presses (for example in viewDidLoad)
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 0.5; //user needs to press for half a second.
[self.mapView addGestureRecognizer:lpgr];
}
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
return;
}
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = touchMapCoordinate;
for (id annotation in self.mapView.annotations) {
[self.mapView removeAnnotation:annotation];
}
[self.mapView addAnnotation:point];
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}