我想创建自定义 MKAnnotationView
(带图像),没有标注,但触摸后可展开。这是我的想法:
1) 首先 MKAnnotation
看起来像这样:
2) 然后在点击它之后它应该展开并且看起来像这样:
我已经开始自定义 MKAnnotationView
并且有一个类:
@interface CustomPinAnnotation : NSObject <MKAnnotation>
类有方法:
-(MKAnnotationView*)annotationView {
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"AnnotationIdentifier"];
annotationView.enabled = YES;
annotationView.image = [[UIImage imageNamed:@"star"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
return annotationView;
}
我尝试做的是将 customView 设置为 MKAnnotationView
的 subview ,但是当我不设置图像时它不会响应(在我考虑之后这是非常合乎逻辑的),但是得到了感觉我在这里做了一些非常讨厌的事情,应该是一种以某种方式覆盖 MKAnnotationView
的方法。
最佳答案
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
enemyAnnotationView.image = [UIImage imageNamed:@"firstImage.png"];
}
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
enemyAnnotationView.image = [UIImage imageNamed:@"SecondImage.png"];
}
尝试像第一种方法那样在 View 中进行注释,以便在您的第一张图像出现时,
第二种方法将在用户选择注释时运行
关于ios - 自定义 MKAnnotationView 可展开,无需标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22708784/