【iPhone Demo】地图自定义大头针

ORIETech 2011-07-29 11:40:24
MKMapView中有一个代理方法- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation可以返回的就是一个view就是大头针;


自定义大头针类


.h文件
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface TTCustomAnnotationView : MKAnnotationView {

}

@end
.m文件
#import "TTCustomAnnotationView.h"


@implementation TTCustomAnnotationView

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
//大头针的图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[imageView setImage:[UIImage imageNamed:@"pin.png"]];
[self addSubview:imageView];
}

return self;
}
- (void)dealloc
{
[super dealloc];
}

代理写发
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

if ([annotation isKindOfClass:[TTCustomMapPin class]]) {
static NSString* kPin = @"pin";
TTCustomAnnotationView* pinView = (TTCustomAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:kPin];

if (!pinView) {
pinView = [[TTCustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kPin];

[pinView setDraggable:YES];
}
return pinView;

}
return nil;
}



欢迎访问:http://www.orietech.com
Wordpress: http://orietech.wordpress.com
...全文
1873 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tubaxiaoyu 2012-01-19
  • 打赏
  • 举报
回复
请查看http://open.mapbar.com/API_ios.jsp 图吧地图ios示例,里面有详细的文档说明
程序员小迷 2012-01-12
  • 打赏
  • 举报
回复
哦,学习了,我以为是个问题
liuqiang1988811 2011-10-14
  • 打赏
  • 举报
回复
楼主用过拖拽大头针的函数没
fugenkong 2011-09-21
  • 打赏
  • 举报
回复
路过。。。~~~
suheart 2011-08-23
  • 打赏
  • 举报
回复
飘过~~~
ORIETech 2011-07-30
  • 打赏
  • 举报
回复
地图自定义大头针

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧