如何制作像4sq应用程序的朋友地图一样的自定义图钉

发布于 2024-11-16 06:50:12 字数 264 浏览 0 评论 0原文

如何制作像foursquare好友地图这样的自定义图钉而不是地图上的图钉?

图片在这里,http://www .socialmedianews.com.au/wp-content/uploads/2010/07/foursquare-friends-map.png

How to make custom pin like foursquare friends map instead of pin on map?

image is here, http://www.socialmedianews.com.au/wp-content/uploads/2010/07/foursquare-friends-map.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

在巴黎塔顶看东京樱花 2024-11-23 06:50:12
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation      {
MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];

 if (!pinView) {
    pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
    pinView.image = [UIImage imageNamed:@"SPOON4.png"];
    pinView.frame = CGRectMake(-30, 0, 70, 67.5); 
    //pinView.animatesDrop = YES; can't animate with custom pin images
    pinView.canShowCallout = YES;


    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton;

} else {
    pinView.annotation = annotation;
}
if (annotation == mapView.userLocation){
    return nil; //default to blue dot
}
return pinView;
}
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation      {
MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];

 if (!pinView) {
    pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
    pinView.image = [UIImage imageNamed:@"SPOON4.png"];
    pinView.frame = CGRectMake(-30, 0, 70, 67.5); 
    //pinView.animatesDrop = YES; can't animate with custom pin images
    pinView.canShowCallout = YES;


    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton;

} else {
    pinView.annotation = annotation;
}
if (annotation == mapView.userLocation){
    return nil; //default to blue dot
}
return pinView;
}
凉风有信 2024-11-23 06:50:12

您需要使用自定义 MKAnnotationView

您可以使用 MKAnnotationView 类
按原样或将其子类化以提供自定义
根据需要的行为。图像属性
类的允许您设置
注释视图的外观
无需直接子类化。你
还可以创建自定义子类作为
方便并使用它们来放置
处于已知状态的注释视图。为了
例如,MKPinAnnotationView
子类初始化内容
图钉图像的注释视图。

You need to use a custom MKAnnotationView.

You can use the MKAnnotationView class
as is or subclass it to provide custom
behavior as needed. The image property
of the class lets you set the
appearance of the annotation view
without subclassing directly. You
might also create custom subclasses as
a convenience and use them to put the
annotation view in a known state. For
example, the MKPinAnnotationView
subclass initializes the contents of
the annotation view to a pin image.

清风不识月 2024-11-23 06:50:12

您想用带框的肖像替换自定义图钉。您可以使用 Quartz 绘制框架,或将框架添加为第二个透明图像。我会执行第二个操作,将以下内容添加到 MKAnnotationView:

- (id)initWithAnnotation:(id <MKAnnotation>)annotation 
         reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        self.opaque = NO;
        self.frame = CGRectMake(0,0, self.portraitImage.size.width, self.portraitImage.size.height);
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
        [self.frameImage drawInRect:CGRectMake(0, 0, frameImage.width, frameImage.height)];
        [self.portraitImage drawInRect:CGRectMake(0, 0, portraitImage.width, portraitImage.height)];
}

You want to replace the custom pin with a framed portrait. You can draw the frame with Quartz, or add the frame as a second transparent image. I would do the second adding the following to MKAnnotationView:

- (id)initWithAnnotation:(id <MKAnnotation>)annotation 
         reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        self.opaque = NO;
        self.frame = CGRectMake(0,0, self.portraitImage.size.width, self.portraitImage.size.height);
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
        [self.frameImage drawInRect:CGRectMake(0, 0, frameImage.width, frameImage.height)];
        [self.portraitImage drawInRect:CGRectMake(0, 0, portraitImage.width, portraitImage.height)];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文