1

我有一个UIImageView动画并接收一个UITapGestureRecognizer. 问题在于动画时,点击手势区域不会随视图移动。我可以点击视图的原始位置并且点击手势被识别。任何人都知道如何在视图移动而不是在其原始位置时识别水龙头?

编辑 1:这就是我设置点击手势识别器的方式:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tapRecognizer.cancelsTouchesInView = YES;
    tapRecognizer.numberOfTapsRequired = 1;
    tapRecognizer.delegate = (id)self;
    [imageView addGestureRecognizer:tapRecognizer];
    imageView.userInteractionEnabled = YES;

由于我的动画持续了几秒钟,有没有办法让手势识别器跟随我的路径?我错过了一个设置吗?

编辑 2:这是我设置动画的代码:

    double width = backgroundImageView.frame.size.width;
    double height = backgroundImageView.frame.size.height;

    CGMutablePathRef path = CGPathCreateMutable();
    double startX = -imageView.frame.size.width;
    double startY = height/4;
    double endX = 3*width;
    double endY = 0;
    double duration = 40;
    CGPathMoveToPoint(path, NULL, startX, startY);
    CGPathAddLineToPoint(path, NULL, endX, endY);
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.duration = duration;
    animation.path = path;
    animation.repeatCount = HUGE_VALF;
    [imageView.layer addAnimation:animation forKey:@"theAnimation"];
4

1 回答 1

2

对于任何有兴趣的人,我解决了我的问题。只需使用NSTimer,检查和更新演示文稿中的UIImageView's :framelayer

CGRect viewLocation = [[[imageView layer] presentationLayer] frame];    
imageView.frame = CGRectMake(viewLocation.origin.x, viewLocation.origin.y, viewLocation.size.width, viewLocation.size.height);

之后,无论我的图像视图在哪里,都可以触摸工作:-)

于 2012-09-10T17:19:20.230 回答