动画annotationViews(循环动画),didSelectAnnotationView不起作用

时间:2015-03-04 03:57:08

标签: ios animation uiview grand-central-dispatch layer

所以我尝试使用以下代码为annotationViews设置动画:

   - (void)mapView:(MKMapView *)mapView
didAddAnnotationViews:(NSArray *)annotationViews

{
    LLAnnotationView *aV;

    for (aV in annotationViews) {

        // Don't pin drop if annotation is user location
        if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
            continue;
        }

        aV.transform = CGAffineTransformMakeScale(0, 0);
        aV.alpha = 0.1;

        dispatch_async(dispatch_get_main_queue(), ^(void){
        [self animateAnnotationView:aV withAnnotationViews:annotationViews];
        });


       }
    }

-(void)animateAnnotationView:(LLAnnotationView*)aV withAnnotationViews:(NSArray*)annotationViews{

#define kDurationBetweenShowUpAnimations 0.4
#define kLoopAnimationDuration 1
#define kAnimationDuration 0.4

    // Initial animation

    [UIView animateWithDuration:kAnimationDuration delay:kDurationBetweenShowUpAnimations*[annotationViews indexOfObject:aV]options:UIViewAnimationOptionCurveLinear animations:^(void){

        aV.transform = CGAffineTransformMakeScale(1.1, 1.1);
        aV.alpha = 1.0;

    }completion:^(BOOL finished){
        [UIView animateWithDuration:kAnimationDuration/2 animations:^(void){

            aV.transform = CGAffineTransformMakeScale(1.0, 1.0);
            aV.alpha = 0.9;

        }completion:^(BOOL finished){

            [UIView animateWithDuration:kAnimationDuration animations:^(void){

                aV.transform = CGAffineTransformMakeScale(1.1, 1.1);
                aV.alpha = 1.0;
            }completion:^(BOOL finished){

                // **LOOP animation**

                [UIView animateWithDuration:kLoopAnimationDuration delay:0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^(void){

                    aV.transform = CGAffineTransformMakeScale(1.0, 1.0);
                    aV.alpha = 0.9;
                }completion:^(BOOL finished){

                }];
            }];
        }];

    }];
}

一切都与动画有关。 但是当我尝试选择注释视图时,很少调用didSelectAnnotationView。

我怀疑这应该是线程相关的。

有没有人知道发生了什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

刚刚找到解决方案。将UIViewAnimationOptionAllowUserInteraction添加到animateWithDuration的选项中:

[UIView animateWithDuration:kLoopAnimationDuration延迟:0选项:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction ...

!!