2

カスタムMKAnnotationクラスを作成しましたが、iOS6がリリースされるまで機能していました。それ以来、私のピンはアップルマップに追加されますが、ドロップアニメーションはありません!これがどのように設定されているのか、それとも私が物事を行う方法に問題があるのでしょうか。マップに注釈を追加するメソッドが呼び出されるまで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

iOS6の新しいAppleMapKitでは、注釈がMKMapViewに追加される順序が少し変更されたようです。

(私自身の場合、以前は注釈を追加し、その直後にマップビューのデリゲートを設定し、iOS 6の前は、実行サイクルの後半まで注釈は表示されませんでしたが、現在はすぐに追加しようとしています。)

そのため、デリゲートが接続される前に注釈が追加されているか、注釈の追加が早すぎてアニメーションが表示されないことが問題である可能性があります。MKMapViewがいつ作成されるか(.xibではなくコードで作成することを前提としています)および注釈を追加するときに関するその他のコードサンプルは、何が問題なのかを明確にするのに役立つ場合があります。

于 2012-10-08T17:48:38.817 に答える