使用CAAnimation启用用户交互? [英] User Interaction Enabled With CAAnimation?

查看:62
本文介绍了使用CAAnimation启用用户交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用基于块的动画的选项字段动画时,允许用户与视图交互非常容易。但在我的程序中,我使用的是CAKeyframeAnimation,我没有看到任何属性来设置用户交互。有没有办法做到这一点?

It is very easy to allow users to interact with views while animating using the options field of block based animation. But in my program I am using a CAKeyframeAnimation and I don't see any properties to set user interaction enabled. Is there any way to do this?

谢谢,

编辑:这是实际代码:

- (void)move
{
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 50, 120);
    for (int i = 0; i < 5; i ++)
        CGPathAddLineToPoint(path, NULL, arc4random() % 320, arc4random() % 480);
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    [animation setPath:path];
    [animation setDuration:10];
    CFRelease(path);
    [self.layer addAnimation:animation forKey:@"move"];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self setAlpha:0];
}


推荐答案

你很可能会触及错误的地方。当图层在屏幕上设置动画时,值永远不会改变,因此视图实际上位于从开头的位置,而不是它在屏幕上显示的位置。

You are most likely touching the wrong place. When the layer animates on screen the value never changes so the view is actually positioned where it was from the beginning, not where it appears on screen.

我做了博客文章几个月前,在如何点击测试动画层。它描述了你要做的确切事情。

I did a blog post a few month ago on how to hit test animating layers. It describes the exact thing that you are trying to do.

你需要在superview中添加触摸处理(或手势识别器)并进行命中测试 presentationLayer 自己确定用户是否点击了视图在屏幕上显示的位置。

You will need to add the touch handling (or gesture recognizer) to the superview and do the hit-testing of the presentationLayer yourself to determine if the user tapped where the view appeared on screen.

这篇关于使用CAAnimation启用用户交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆