小编Art*_*hur的帖子

如何使用MapKit快速旋转自定义userLocationAnnotationView图像?

我正在尝试找到一种使用MapKit在地图上显示用户方向的方法。MapKit的本机方法总是旋转整个地图。由于用户位置也是MKAnnotationView,因此我决定创建一个特定的类来覆盖它并使用特定的图像(带有箭头)。

class UserLocationAnnotationView: MKAnnotationView {

override init(frame: CGRect) {
    super.init(frame: frame)
}

override init(annotation: MKAnnotation!, reuseIdentifier: String!) {

    super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)

    var frame = self.frame
    frame.size = CGSizeMake(130, 130)
    self.frame = frame
    self.backgroundColor = UIColor.clearColor()
    self.centerOffset = CGPointMake(-30, -50)

}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
override func drawRect(rect: CGRect) {
    // Drawing code
    UIImage(named: "userLocation.png")?.drawInRect(CGRectMake(65, 65, …
Run Code Online (Sandbox Code Playgroud)

direction mapkit mkannotationview ios swift

3
推荐指数
1
解决办法
1210
查看次数

标签 统计

direction ×1

ios ×1

mapkit ×1

mkannotationview ×1

swift ×1