【发布时间】:2019-11-21 22:20:40
【问题描述】:
MKAnnotationView 有 2 个图像状态,它们是 selected 和 deselected。问题是这两种状态之间的过渡很差。网上没有太多关于此的内容,而且我通常在转换时遇到问题。
这是我正在使用的MKAnnotationView:
class CustomPinView: MKAnnotationView {
func updateImage() {
guard let mapAnnotation = annotation as? MapAnnotation else {return}
if let selectedImageName = mapAnnotation.selectedImageName, isSelected {
image = UIImage(inCurrentBundleWithName: selectedImageName)
} else if let imageName = mapAnnotation.imageName {
image = UIImage(inCurrentBundleWithName: imageName)
} else {
image = nil
}
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
updateImage()
}
override var annotation: MKAnnotation? {
didSet {
updateImage()
}
}
}
【问题讨论】:
标签: swift mapkit mkannotation mkannotationview