gpt4 book ai didi

objective-c - 自定义 MKAnnotationView masksToBounds=YES 和 canShowCallout=YES 异常

转载 作者:行者123 更新时间:2023-12-04 02:52:07 27 4
gpt4 key购买 nike

如何在自定义 MKAnnotationView 上正确设置半径并允许标注?这会引发异常:

来 self 的自定义 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;
}

在呈现 map View 的类中:

- (MKAnnotationView *)mapView:(MKMapView *)mView viewForAnnotation:(id <MKAnnotation>)annotation
{
// logic to dequeue annotation views, etc.

annotationView.canShowCallout = YES;
return annotationView;
}

异常(exception)情况:

* 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: terminate called throwing an exception (lldb)

最佳答案

我找到了一个解决方案。我创建了一个颜色清晰的 OuterAnnotationView,并在初始化时向 OuterAnnotationView 添加了一个 subview 。我添加的 subview (内部)我可以设置cornerRadius 和 masksToBounds=YES 现在一切正常。

关于objective-c - 自定义 MKAnnotationView masksToBounds=YES 和 canShowCallout=YES 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17473647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com