ios – 如何使用Xcode 6(Swift)添加引脚(注释)
发布时间:2020-12-15 01:40:00 所属栏目:百科 来源:网络整理
导读:我是一个陌生的语言的新手,还没有使用mapkit做过应用程序.但是我已经设置了地图和区域,但是我挂断了如何允许用户添加引脚. 让我澄清一点,我不知道甚至从哪里开始,我现在所有的(针对)是我的变量,但是我甚至不确定是否正确.任何帮助将不胜感激! 我拥有的… va
我是一个陌生的语言的新手,还没有使用mapkit做过应用程序.但是我已经设置了地图和区域,但是我挂断了如何允许用户添加引脚.
让我澄清一点,我不知道甚至从哪里开始,我现在所有的(针对)是我的变量,但是我甚至不确定是否正确.任何帮助将不胜感激! 我拥有的… var MyPins:MKPinAnnotatoinView! …… override func viewDidLoad() { super.viewDidLoad() Mapview代码 ….. 解决方法
你的pin变量是正确的.现在你只需要添加这个注释到MKMapView.
您还可以为MKAnnotation创建自定义类,以将定制注释添加到地图视图. MapExampleiOS8的beta演示=>哪个支持Swift 2.1 按照以下步骤: 1.将MapKit.framework添加到项目中. 2.创建Storyboard变量IBOutlet的地图视图控件或在视图控制器中创建它.设置此变量的委托以覆盖它的委托方法: 添加委托签名以查看控制器界面: class ViewController: UIViewController,MKMapViewDelegate { override func viewDidLoad() { super.viewDidLoad() // Set map view delegate with controller self.mapView.delegate = self } } 覆盖其委托方法: 这里我们需要重写mapView(_:viewForAnnotation :)方法来显示地图上的注释引脚. func mapView(mapView: MKMapView,viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if (annotation is MKUserLocation) { return nil } if (annotation.isKindOfClass(CustomAnnotation)) { let customAnnotation = annotation as? CustomAnnotation mapView.translatesAutoresizingMaskIntoConstraints = false var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("CustomAnnotation") as MKAnnotationView! if (annotationView == nil) { annotationView = customAnnotation?.annotationView() } else { annotationView.annotation = annotation; } self.addBounceAnimationToView(annotationView) return annotationView } else { return nil } } 4.将MKPointAnnotation添加到地图视图. 您可以在地图视图中添加针脚到位置.为了简单起见,添加代码到viewDidLoad()方法. override func viewDidLoad() { super.viewDidLoad() // Set map view delegate with controller self.mapView.delegate = self let newYorkLocation = CLLocationCoordinate2DMake(40.730872,-74.003066) // Drop a pin let dropPin = MKPointAnnotation() dropPin.coordinate = newYorkLocation dropPin.title = "New York City" mapView.addAnnotation(dropPin) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |