我正在做一个功能,当用户按下按钮时,地图会指示用户'脉冲动画注释的当前位置。
SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
region.zoomLevel = 14;
self.mapView.visibleRegion = region;
SKAnnotation *CurrentLocationAnnotation = [SKAnnotation annotation];
CurrentLocationAnnotation.identifier = 1;
//CurrentLocationAnnotation.annotationType = SKAnnotationTypeMarker;
CurrentLocationAnnotation.location = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
SKAnimationSettings *CurrentLocationanimationSettings = [SKAnimationSettings animationSettings];
CurrentLocationanimationSettings.animationType = SKPulseAnimation;
CurrentLocationanimationSettings.animationEasingType = SKAnimationEaseLinear;
CurrentLocationanimationSettings.duration = 7000;
[self.mapView addAnnotation:CurrentLocationAnnotation withAnimationSettings:CurrentLocationanimationSettings];
我也在模拟器和iphone上尝试过,他们两个都没有工作。 我该如何解决?提前谢谢
答案 0 :(得分:1)
CLLocationCoordinate2D cordinate;
- (void)viewDidLoad {
[super viewDidLoad];
self.mapview.delegate=self;
self.locationManager.delegate = self
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
[self.mapview setMapType:MKMapTypeSatellite];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 54, 122, 21)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.3];
label.text = @"title";
//create our view for the image
UIImageView *coloredView1 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
coloredView1.image = [UIImage imageNamed:@"demo.png"];
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
view1.backgroundColor = [UIColor clearColor];
[view1 addSubview:label];
[view1 addSubview:coloredView1];
//create our view for the background image
UIImageView *coloredView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 110)];
coloredView2.image = [UIImage imageNamed:@"mapMarker"];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
view1.backgroundColor = [UIColor clearColor];
[view2 addSubview:coloredView2];
[view2 addSubview:view1];
//create our view for the background image
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 200)];
view3.backgroundColor = [UIColor clearColor];
[view3 addSubview:view2];
SKAnnotationView *annotationView = [[SKAnnotationView alloc] initWithView:customAnnotationView reuseIdentifier:@"reusableIdentifier"];
SKAnnotation *annotation = [SKAnnotation annotation];
annotation.identifier = 123456;
annotation.location = region.center;
annotation.annotationView = annotationView;
[self.mapView addAnnotation:annotation withAnimationSettings:[SKAnimationSettings animationSettings]];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
static NSString *identifier = @"myAnnotation";
DraggableAnnotationView * annotationView = (DraggableAnnotationView *)[self.mapview dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[DraggableAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.image = [UIImage imageNamed:@"ic_map_pin.png"];
}
else
{
annotationView.annotation = annotation;
}
annotationView.delegate = self;
return annotationView;
}
如果此代码对您有帮助,请投票...谢谢