2

我创建了一个自定义的 MKAnnotation 类并且它一直在工作——直到 iOS 6 出现。从那时起,我的图钉被添加到苹果地图中,但现在没有放置动画!这是它的设置方式还是我做事的方式可能存在问题。在调用将注释添加到地图的方法之前,我设置了 1 秒的延迟,因此我可以查看放置动画是否在视图出现之前实际发生 - 尽管如此,引脚只是突然出现而没有掉落。这是我正在使用的代码:

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation*)annotation
{
    NSLog(@"the annotation ID is: %@", annotation.ID);
    MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation   reuseIdentifier:@"current"];

    UIButton *goToObjectButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    [goToObjectButton addTarget:self action:@selector(goToObjectClick:)  forControlEvents:UIControlEventTouchUpInside];


    MyPin.pinColor = MKPinAnnotationColorRed;
    MyPin.rightCalloutAccessoryView = goToObjectButton;
    MyPin.draggable = NO;
    MyPin.highlighted = YES;
    MyPin.animatesDrop=YES;
    MyPin.canShowCallout = YES;

    return MyPin;
}
4

3 回答 3

3

我还发现,在 iOS6 中,MKMapView 上显示的顺序/时间发生了变化。我曾经在 viewDidLoad 中将我的注释添加到地图中,这在 iOS5 中运行良好,但在 iOS6 中,引脚不会掉落,它们只是出现。我现在已将代码移至 viewDidAppear 并且图钉现在为上方的水滴设置动画。然而,它们都同时下降,而不是像在 iOS5 中那样单独下降。

于 2012-11-05T10:22:53.017 回答
3

MkMappin 下拉弹跳动画作品 - Prem Kumar(iOS 开发者)

-(void)addPinWithTitle:(NSString *)title AndCoordinate:(NSString     *)strCoordinate
{
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
// clear out any white space
strCoordinate = [strCoordinate stringByReplacingOccurrencesOfString:@" " withString:@""];
// convert string into actual latitude and longitude values
NSArray *components = [strCoordinate componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];

// setup the map pin with all data and add to map view
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);

mapPin.title = [title valueForKey:@"restaurantBranchName"];
mapPin.coordinate = coordinate;
[locationMapView addAnnotation:mapPin];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [locationMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
    return annotationView;
else
{
    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                    reuseIdentifier:AnnotationIdentifier];
    annotationView.canShowCallout = YES;
    UIImage *img = [UIImage imageNamed:@"orange_restaurant"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
    imageView.frame=CGRectMake(0, 0, 40, 40);
    imageView.contentMode=UIViewContentModeScaleAspectFit;
    imageView.center = annotationView.center;
    [annotationView addSubview:imageView];


    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    annotationView.rightCalloutAccessoryView = rightButton;

    UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    rightView.backgroundColor=ThemeColor;
    rightView.layer.cornerRadius=rightView.frame.size.width/2;
    annotationView.leftCalloutAccessoryView=rightView;

    annotationView.canShowCallout = YES;
    annotationView.draggable = YES;
    return annotationView;
}
return nil;

}

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;

for (aV in views) {
    // Don't pin drop if annotation is user location
    if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
        continue;
    }
    // Check if current annotation is inside visible map rect, else go to next one
    MKMapPoint point =  MKMapPointForCoordinate(aV.annotation.coordinate);
    if (!MKMapRectContainsPoint(mapView.visibleMapRect, point)) {
        continue;
    }

    CGRect endFrame = aV.frame;
    aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height);
    [UIView animateWithDuration:0.5 delay:0.04*[views indexOfObject:aV] options: UIViewAnimationOptionCurveLinear animations:^{

        aV.frame = endFrame;

    }completion:^(BOOL finished){
        if (finished) {
            [UIView animateWithDuration:0.5 animations:^{
                aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height/6, aV.frame.size.width, aV.frame.size.height);
            }completion:^(BOOL finished){
                if (finished) {
                    [UIView animateWithDuration:0.5 animations:^{
                        aV.frame = endFrame;
                    }];
                }
            }];
        }
    }];
}

}

于 2016-02-16T12:09:40.863 回答
1

似乎在 iOS 6 中使用新的 Apple MapKit,将注释添加到 MKMapView 的顺序发生了一些变化。

(在我自己的情况下,我曾经添加注释,然后在 iOS 6 之后和之前立即设置地图视图的委托,注释直到运行周期的后期才出现,但现在他们尝试立即添加。)

因此,这可能是一个问题,要么是在连接代理之前添加注释,要么你太早添加注释而没有看到动画。有关何时创建 MKMapView(假设您是在代码中而不是在 .xib 中)以及何时添加注释的更多代码示例可能有助于澄清问题所在。

于 2012-10-08T17:48:38.817 回答