【问题标题】:Animating annotationViews (loop animation), didSelectAnnotationView doesn't work动画annotationViews(循环动画),didSelectAnnotationView 不起作用
【发布时间】:2015-05-04 23:11:59
【问题描述】:

所以我尝试使用以下代码为我的 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 很少被调用。

我怀疑这应该与线程相关。

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

谢谢。

【问题讨论】:

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


    【解决方案1】:

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

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

    !!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 2017-04-22
      相关资源
      最近更新 更多