iOS mapView animatesDrop

时间:2013-04-08 23:32:32

标签: ios xcode animation annotations mkmapview

在我的mapview中,我目前拥有bool animatesDrop,注释设置为NO。这是因为在viewWillAppear期间绘制mapView注释时,我不会对它们进行动画处理。但是,我还有一个刷新按钮用于重新绘制注释,并希望它们在被推动时动画(删除)。有没有办法实现这个?感谢。

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    if ([annotation isKindOfClass:[MKUserLocation class]]) {

        return nil;
    }

    MyPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];

    UIButton *calloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    UIButton *directionsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    directionsButton.frame = CGRectMake(0, 0, 23, 23);
    [directionsButton setBackgroundImage:[UIImage imageNamed:@"directions.png"] forState:UIControlStateNormal];

    MyPin.leftCalloutAccessoryView = directionsButton;
    MyPin.rightCalloutAccessoryView = calloutButton;
    MyPin.draggable = NO;
    MyPin.highlighted = NO;
    MyPin.animatesDrop= YES;
    MyPin.canShowCallout = YES;

    return MyPin;
}

2 个答案:

答案 0 :(得分:2)

“Hard Ball”方法是建立一个在viewWillAppear中设置为false的布尔属性,但在按钮的操作中设置为true。将MyPin.animatesDrop设置为viewForAnnotation中的属性。不知道任何“优雅”的解决方案。

答案 1 :(得分:0)

使用代码

删除所有注释
[self.mapView removeAnnotations:self.usersAnnotationArray];

再次注释到mapview,使用BOOL变量检查按钮并设置

MyPin.animatesDrop= YES;

in delagate method

    -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
......
......
......
if(_IsButtonClikced)
{
    MyPin.animatesDrop= YES;

}
else
{
    MyPin.animatesDrop= NO;

}

................
.......
.....
}