主要使用方法
[Objective-C] 查看源文件 复制代码
#import "SVViewController.h" #import <MapKit/MapKit.h> #import "SVAnnotation.h" #import "SVPulsingAnnotationView.h" @interface SVViewController () <MKMapViewDelegate> @property (nonatomic, strong) MKMapView *mapView; @end @implementation SVViewController - (void)loadView { self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; } - (void)viewDidLoad { [super viewDidLoad]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView.delegate = self; [self.view addSubview:self.mapView]; } - (void)viewDidAppear:(BOOL)animated { CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(39.26, 116.0); MKCoordinateRegion region = MKCoordinateRegionMake(coordinate, MKCoordinateSpanMake(0.1, 0.1)); [self.mapView setRegion:region animated:NO]; SVAnnotation *annotation = [[SVAnnotation alloc] initWithCoordinate:coordinate]; annotation.title = @"Current Location"; annotation.subtitle = @"Montréal, QC"; [self.mapView addAnnotation:annotation]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { if([annotation isKindOfClass:[SVAnnotation class]]) { static NSString *identifier = @"currentLocation"; SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if(pulsingView == nil) { pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; pulsingView.annotationColor = [UIColor colorWithRed:0.678431 green:0 blue:0 alpha:1]; pulsingView.canShowCallout = YES; } return pulsingView; } return nil; } @end

相关代码
代码贡献英雄榜
用户名
下载数
- 1 李世铿 87757
- 2 code4app 75221
- 3 Torr 27565
- 4 刘雨雷 5965
- 5 shareiOS 5741
- 6 tab-ba 5035
- 7 半吱湮 4798
- 8 Rockets_Chen 4672
- 9 xiaoxiaohong1 4110
- 10 Zws丶 4079