简单理解MapView 以及 设置 MKAnnotationView

MKMapView  相当于一个容器 。可以展示  MKAnnotationView..

要使用它需要设置 数据源代理  

    _mapView.delegate = self;

 它的数据源对象就是 

符合   MKAnnotation   协议的对象 

包含

@protocol MKAnnotation <NSObject>

// Center latitude and longitude of the annotion view.
// The implementation of this property must be KVO compliant.
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@optional

// Title and subtitle for use by selection UI.
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

// Called as a result of dragging an annotation view.
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate NS_AVAILABLE(10_9, 4_0);

@end

 

这里不得不关联下 最常用的tableView 控件 

它也需要数据源   和 代理 

需要把数据源  加载到 tableViewCell 上 显示

对比mapView ,它的数据源是  (id<MKAnnotation>)annotation

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id<MKAnnotation>)annotation {

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath...

对比下  是不是很相识 。。

同样的还有 uipickerView

下面实现自定义  MKAnnotationView 跟自定义UITabelViewcell  差不多

http://www.codigator.com/tutorials/advanced-mapkit-tutorial-for-ios-custom-callout/

 

实现  不点击annotation 也能显示calloutview 

添加 代理方法

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
        
    for (MKAnnotationView *annoView in views) {
                
        MKAnnotation *anno = annoView.annotation;
                [mv selectAnnotation:anno animated:YES]; 
    }
}

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值