【发布时间】:2015-01-20 12:48:41
【问题描述】:
这是我之前的帖子,我将图像设置为注释视图引脚
Swift - setting different images from array to annotation pins
现在我遇到了在注释视图图像上设置圆角的问题。
cannot show callout with clipsToBounds enabled swift
似乎我必须在圆角或显示标注之间做出选择,我真的不明白为什么这两个不能出现。有没有办法做到这一点? 这是我的 viewForAnnotation 函数:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is RestaurantAnnotation) {
return nil
}
let reuseId = "restaurant"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = false
}
else {
anView.annotation = annotation
}
let restaurantAnnotation = annotation as RestaurantAnnotation
if (restaurantAnnotation.image != nil) {
anView.image = restaurantAnnotation.image!
anView.layer.masksToBounds = true
anView.layer.cornerRadius = (anView.frame.size.height)/10.0
}
else {
// Perhaps set some default image
}
return anView
}
提前感谢您的帮助!
【问题讨论】:
-
看看这个自定义调用演示 - stackoverflow.com/questions/27519517/…
-
我想情况有点不同,因为他试图在标注字段内显示图像,我用图像更改了图钉,并且没有圆角一切正常。
标签: ios swift mapkit mkannotation mkannotationview