ios – 当我为UIImageView设置动画时,UITapGestureRecognizer不起作用

前端之家收集整理的这篇文章主要介绍了ios – 当我为UIImageView设置动画时,UITapGestureRecognizer不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我想为UI ImageView设置动画时,添加到它的UITapGestureRecognizer无法工作.为什么???
-(void) testTap:(id)sender {
    NSLog(@"Test tap...");
}

-(void) testSlide {
    UITapGestureRecognizer* testTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testTap:)] autorelease];
    testTap.numberOfTapsrequired = 2;

    UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_slide"]] autorelease];
    [imageView setFrame:CGRectMake(40,40,200,200)];
    imageView.userInteractionEnabled = YES;
    imageView.multipleTouchEnabled = YES;
    [imageView addGestureRecognizer:testTap];

    [self.view addSubview:imageView];


    // When I add the following code,the UITapGestureRecognizer will not work. WHY???
    imageView.alpha = 0;
    CGAffineTransform t = imageView.transform;
    if (CGAffineTransformIsIdentity(t)) {
        UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut;
        [UIView animateWithDuration:1.0 delay:0 options:options animations:^{
            imageView.alpha = 1.0;
        } completion:^(BOOL finished) {
            if (finished) {
                [UIView animateWithDuration:1.0 delay:2.0 options:options animations:^{
                imageView.alpha = 0.4;
                } completion:^(BOOL finished) {
                    if (finished) {
                        [imageView removeFromSuperview];
                    }
                }];
            }
        }];
    }
}

解决方法

您需要在动画期间允许用户交互.
UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;
原文链接:https://www.f2er.com/iOS/335287.html

猜你在找的iOS相关文章