如何在自定义 MKAnnotationView 上正确设置半径并允许标注?这会引发异常:
从我的自定义 MKAnnotationView 类:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.frame = CGRectMake(0, 0, 30, 30);
self.opaque = NO;
self.multipleTouchEnabled = NO;
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = 5;
self.layer.masksToBounds = YES;
self.layer.borderColor = [UIColor blueColor].CGColor;
self.layer.borderWidth = 1.0f;
self.layer.shadowOffset = CGSizeMake(1, 0);
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = .25;
}
return self;
}
在我展示地图视图的班级中:
- (MKAnnotationView *)mapView:(MKMapView *)mView viewForAnnotation:(id <MKAnnotation>)annotation
{
// logic to dequeue annotation views, etc.
annotationView.canShowCallout = YES;
return annotationView;
}
例外:
* Terminating app due to uncaught exception 'NSGenericException', reason: '> cannot show callout with clipsToBounds enabled' * First throw call stack: (0x1c04012 0x1689e7e 0x4eab5f 0x4ebcaf 0x4ebaea 0x4ebf03 0x4d7e24 0x4d7e54 0x4da610 0x5a7e 0x221853f 0x222a014 0x221a7d5 0x1baaaf5 0x1ba9f44 0x1ba9e1b 0x1a617e3 0x1a61668 0x5cdffc 0x29ad 0x28d5 ) libc++abi.dylib:终止调用抛出异常 (lldb)