在做动画的控件不触发手势事件问题及解决方案

1.首先排除表格的父试图是否能交互(userInteractionEnabled);
2.其次排除表格是否能交互(userInteractionEnabled);
3.再次排查表格是否被其它透明可交互控件遮盖(Xcode强大的多视图立体分层显示View UI Herarchy)。
4.是否表格超过父试图的范围(Xcode强大的多视图立体分层显示View UI Herarchy)。
5.若以上都没有问题,那么很可能是你的表格的父试图设置了手势,手势的优先级高于表格点击事件。在容器页面(一个容器包含多个控制器页面)更容易出现该问题。
首先设置动画的可交互属性:UIViewAnimationOptionAllowUserInteraction或UIViewKeyframeAnimationOptionAllowUserInteraction。removedOnCompletion设置为NO

    [UIView beginAnimations:@"Marquee" context:NULL];
    //动画时长
    [UIView setAnimationDuration:2.0];
    //动画节奏
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction];
    //重复次数
    [UIView setAnimationRepeatCount:1];

    self.decribeImageView.alpha = 1.0;
    self.describeTitleLabel.alpha = 1.0;
    [UIView animateKeyframesWithDuration: 5.0 delay: 0 options: UIViewKeyframeAnimationOptionCalculationModeLinear|UIViewKeyframeAnimationOptionAllowUserInteraction animations: ^{
        self.decribeImageView.frame = CGRectMake(self.decribeImageViewEdge+FULL_WIDTH, self.decribeImageViewTop, SCREEN_WIDTH -self.decribeImageViewEdge*2, self.decribeImageViewHeight*FULL_WIDTH/375);
        [UIView addKeyframeWithRelativeStartTime: 0 relativeDuration: 1.0/(5*4) animations: ^{
            self.decribeImageView.frame = CGRectMake(self.decribeImageViewEdge, self.decribeImageViewTop, SCREEN_WIDTH -self.decribeImageViewEdge*2, self.decribeImageViewHeight*FULL_WIDTH/375);
        }];

        [UIView addKeyframeWithRelativeStartTime: (1 - 1.0/(5*4) - 0.001) relativeDuration: 1.0/(5*4) animations: ^{
            self.decribeImageView.frame = CGRectMake(-self.decribeImageViewEdge-FULL_WIDTH, self.decribeImageViewTop, SCREEN_WIDTH -self.decribeImageViewEdge*2, self.decribeImageViewHeight*FULL_WIDTH/375);
        }];
        
        [UIView addKeyframeWithRelativeStartTime: (1 - 0.001) relativeDuration:0.001 animations: ^{
            self.decribeImageView.alpha = 0;
            self.describeTitleLabel.alpha = 0;
        }];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    animation.values = @[@0.0, @1.0, @1.0];
    animation.keyTimes = @[[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0]];
    
    CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animation];
    opacityAnimation.keyPath = @"opacity";
    opacityAnimation.values = @[@0.0, @1.0];
    group.animations = @[animation, opacityAnimation];
    group.duration = 2.0;
    group.delegate = self;
    group.repeatCount = 1.0;
    
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    [self.diceAnimatedImageView.layer addAnimation:group forKey:@"diceAnimatedImageViewAnimation"];

若还不行就在动画控件上增加一个透明按钮,添加按钮事件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值