MKAnnotationView添加自定义大头针
#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "RNAnnocation.h"
#import "RNAnnotationView.h"
@interface ViewController () <MKMapViewDelegate> // 添加代理
- (IBAction)addAnnocation:(UIButton *)sender;
@property (nonatomic, strong) MKMapView *mapView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
self.mapView = mapView;
mapView.delegate = self; // 设置代理
mapView.userTrackingMode = MKUserTrackingModeFollow ;
[self.view addSubview:mapView];
}
//添加自定义大头方法2 封装
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RNAnnocation *)annotation
{
if (![annotation isKindOfClass:[RNAnnocation class]]) return nil; //返回 nil 按系统默