【发布时间】:2015-02-15 10:36:19
【问题描述】:
所以我试图复制以下场景(半透明注释视图):
我已经尝试了以下实现,但没有成功:
1- 创建不透明度为 30% 的自定义图像并添加到地图中 ---> 结果:图像保持不透明。
代码:
-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
LLAnnotation *myA = (LLAnnotation*) annotation;
self.accessibilityLabel = myA.title;
self.annotation = myA;
self.enabled = YES;
self.canShowCallout = YES;
self.centerOffset = CGPointMake(5,-10);
self.backgroundColor = [UIColor yellowColor];
self.image = [UIImage imageNamed:@"circle"];
}
return self;
}`
然后将其添加到 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation_
2- 向 AnnotationView 添加子层并清除它 ---> 结果:不显示任何注释。
代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation_
{
if (annotation_ == mapView.userLocation) return nil;
MKAnnotationView *m = [[MKAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier:@"default"];
// m.backgroundColor = [UIColor clearColor];
CALayer *layer = [[CALayer alloc]init];
layer.frame = m.frame;
layer.backgroundColor = [UIColor lightGreenColor].CGColor;
[m.layer addSublayer:layer];
m.layer.cornerRadius = m.frame.size.width/2;
m.layer.borderWidth = 2;
m.layer.masksToBounds = YES;
return m;
}
我在想在注释之上添加 MKOverlays 可能是一种解决方法,但我相信它不应该是要走的路。
是否有人对如何实现此功能有其他建议?
【问题讨论】:
标签: ios iphone mkmapview calayer mkannotationview