DSCenterPinMapView0.1.2

DSCenterPinMapView0.1.2

Daniel Esteban Salinas维护。



  • Daniel Esteban Salinas

DSCenterPinMapView

Version License Language Supports Platform

示例

需求

  • iOS 11.0+
  • Xcode 11.6

安装

DSCenterPinMapView 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod 'DSCenterPinMapView'

用法

  1. 将视图的类从 UIView 改为 DSCenterPinMapView
  2. 程序化地
let pinMapView = DSCenterPinMapView(frame: myFrame)
let pinMapView = DSCenterPinMapView(frame: myFrame)

自定义

固定图像

将中心固定图像视图中的图像居中,以分配自定义固定资产

pinMapView.pinImage = UIImage(named: "my-pin-image")
阴影图像

将中心阴影图像视图中的图像居中,以分配自定义阴影资产

pinMapView.shadowImage = UIImage(named: "my-shadow-image")
拖动时阴影图像

如果指定,则当用户拖动地图时,中心阴影将更改为此图像

pinMapView.shadowImageWhenDragged = UIImage(named: "my-optional-second-shadow-image")
阴影透明度

中心阴影图像视图的透明度自定义

pinMapView.shadowAlpha = 0.8
中心点和阴影偏移

如果您想调整固定和阴影的自定义资产,可以设置不同的偏移量

pinMapView.pinOffsetY = 13
pinMapView.shadowOffsetX = 12
pinMapView.shadowOffsetY = 10

是否拖动

如果你想知道地图是否正在移动

委派

你可以实现DSCenterPinMapView的委托,以实现自己的didStartDragging和didEndDragging功能。

pinMapView.delegate = self

extension MyViewController: DSCenterPinMapViewDelegate {

    func didStartDragging() {
        // My custom actions
    }

    func didEndDragging() {
        // My custom actions
        selectedLocation = pinMapView.mapview.centerCoordinate
    }

}

你还可以在保持DSCenterPinMapView核心功能的同时,通过使用MKMapViewDelegate中的updateDragging()设置自己的MKMapView委托。

pinMapView.mapview.delegate = self

extension MyViewController: MKMapViewDelegate {

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        // My custom implementation
    }

    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        // My custom implementation
    }

    func mapView(_ mapView: MKMapView, regionWillChangeAnimated animated: Bool) {
        // My custom implementation
        pinMapView.updateDragging() // Place this code to keep DSCenterPinMapView delegate functionality
    }

    func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
        // My custom implementation
        pinMapView.updateDragging() // Place this code to keep DSCenterPinMapView delegate functionality
    }

}

移动标记点动画

如果你想在你拖拽标记点的时候对其进行动画处理,你应该使用UIImageView动画。例如:

pinMapView.delegate = self

let pinImages = (1...36).map { UIImage(named: "pin-\($0)")! }
pinMapView.pin.pin.animationImages = pinImages
pinMapView.pin.pin.animationDuration = 0.8

pinMapView.delegate = self

extension MyViewController: DSCenterPinMapViewDelegate {

    func didStartDragging() {
        // My custom actions
        pinMapView.pin.pin.startAnimating()
    }

    func didEndDragging() {
        // My custom actions
        pinMapView.pin.pin.stopAnimating()
    }

}

作者

Daniel Esteban Salinas Suárez, [email protected]

许可

DSCenterPinMapView在MIT许可下提供。更多信息请参阅LICENSE文件。