iPhone:MKMapAnnotationView:当前位置与其他图钉具有相同的注释视图。如何让它独一无二?
我使用以下方法在我的地图视图上显示 MKAnnotation 视图。但我这样做时,用户的当前位置也具有与其他引脚相同的视图。如何使当前位置具有独特的图钉颜色
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"currentloc"];
//annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:nil/*@selector(checkButtonTapped:event:)*/
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = myDetailButton;
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
Im using the following method to show MKAnnotation View on my mapView. But wehn I do that the current location of the user is also given the same view as the other pins. How can I make the current location a Unique pin color
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"currentloc"];
//annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:nil/*@selector(checkButtonTapped:event:)*/
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = myDetailButton;
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
viewForAnnotation
方法中,检查注释是否是 MKUserLocation。如果是,则返回nil
:In your
viewForAnnotation
method, check to see if the annotation is an instance of MKUserLocation. If it is, returnnil
: