相关疑难解决方法(0)

MKMapView:自定义视图而不是注释引脚

我想在我的MKMapView而不是小石头上显示图像.有人可以在这里放一些有用的代码,或告诉如何做到这一点?

谢谢!

编辑

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil; 
if(annotation != mapView.userLocation) 
{
    static NSString *defaultPinID = @"com.invasivecode.pin";
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
                                      initWithAnnotation:annotation reuseIdentifier:defaultPinID];

    pinView.pinColor = MKPinAnnotationColorGreen; 
    pinView.canShowCallout = YES;
    pinView.animatesDrop = YES;
    pinView.image = [UIImage imageNamed:@"pinks.jpg"];    //as suggested by Squatch
} 
else {
    [mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Run Code Online (Sandbox Code Playgroud)

我期待我的图像pinks.jpg在地图上,固定位置而不是默认的针视图(摇针形状).但我仍然得到了引脚的默认图像.

objective-c mkmapview mkannotation ios swift

61
推荐指数
2
解决办法
7万
查看次数

如何使用MKAnnotationView创建自定义"pin-drop"动画?

我有一个实例,MKMapView并希望使用自定义注释图标,而不是MKPinAnnotationView提供的标准图钉图标.所以,我已经设置了一个名为CustomMapAnnotation的MKAnnotationView的子类,并且重写-(void)drawRect:了绘制CGImage.这有效.

当我尝试复制.animatesDropMKPinAnnotationView提供的功能时出现问题; 当注释被添加到MKMapView实例时,我希望我的图标能够逐渐显示,从上到下以及从左到右顺序显示.

这是 - (void)drawRect:用于CustomMapAnnotation,当你只绘制UIImage(这是第二行所做的)时它可以工作:

- (void)drawRect:(CGRect)rect {
 [super drawRect:rect];
 [((Incident *)self.annotation).smallIcon drawInRect:rect];
 if (newAnnotation) {
  [self animateDrop];
  newAnnotation = NO;
 }
} 
Run Code Online (Sandbox Code Playgroud)

添加animateDrop方法时出现问题:

-(void)animateDrop {
 CGContextRef myContext = UIGraphicsGetCurrentContext();

 CGPoint finalPos = self.center;
 CGPoint startPos = CGPointMake(self.center.x, self.center.y-480.0);
 self.layer.position = startPos;

 CABasicAnimation *theAnimation;
 theAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
 theAnimation.fromValue=[NSValue valueWithCGPoint:startPos];
 theAnimation.toValue=[NSValue valueWithCGPoint:finalPos];
 theAnimation.removedOnCompletion = NO;
 theAnimation.fillMode = kCAFillModeForwards;
 theAnimation.delegate = self;
 theAnimation.beginTime = 5.0 * (self.center.x/320.0);
 theAnimation.duration = 1.0;
 [self.layer addAnimation:theAnimation …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation mapkit mkpinannotationview

24
推荐指数
4
解决办法
3万
查看次数

MKPinAnnotationView自定义图像被带有动画下落的图钉替换

我在MapView上显示用户头像图像.如果在没有动画的情况下渲染它们,它们似乎正在工作,但是我想为它们的动画制作动画.如果我将pinView.animatesDrop设置为true,那么我将丢失头像并将其替换为pin.如何在不使用针的情况下为我的头像添加动画效果?

这是我正在使用的viewForAnnotation方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];

    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
    }
    else
        pinView.annotation = annotation;

    //If I set this to true, my image is replaced by the pin
    //pinView.animatesDrop = true;

    //I'm using SDWebImage
    [pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    //Adding a nice drop shadow here
    pinView.layer.shadowColor = [UIColor blackColor].CGColor;
    pinView.layer.shadowOffset = CGSizeMake(0, 1);
    pinView.layer.shadowOpacity = 0.5;
    pinView.layer.shadowRadius = 3.0;

    return pinView; …
Run Code Online (Sandbox Code Playgroud)

objective-c mkpinannotationview mkmapview ios

10
推荐指数
1
解决办法
2万
查看次数