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

标签 objective-c ios6 uiview mkmapview mkannotationview

如何在自定义 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/

相关文章:

ios - UIButton 在 iOS 5 中不调用操作但在 iOS 6 中工作

uitableview - indexPathForCell 在 IOS 7 下返回 NULL,在 IOS 6 下工作正常

ios - 单边角的反向 UIBezierPath

iphone - 如何在 uitextfield 委托(delegate)方法中获取单元格索引路径?

ios - 新闻API可以在应用程序中使用吗?

objective-c - 我可以从 objective-c 中的特定网页中提取内容吗?

ios - UICollectionView for Springboard 像文件夹

objective-c - 单例属性不能在外部类中使用

ios - 拼贴应用程序的自定义 UIView

ios - 在 View Controller 中访问 UIView 子类