检测触摸动画(移动)视图
问题描述:
我遇到的问题是检测在屏幕上动画移动的UIView
或UIViewController
上的触摸。我试过UITapGesture
,touchesbegan
和UIbutton
。但是我发现问题在于使用动画块时。视图的位置设置为其结束位置,移动时无法触摸。 (您可以触摸视图将要停止的位置以及读取的触摸位置)。我已经尝试过UIView
动画块的动画。我也尝试使用CAKeyframeAnimation
,但都具有相同的结果。检测触摸动画(移动)视图
[UIView animateWithDuration:10 delay:1 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction) animations:^{
[testViewController.view setFrame:CGRectMake(900, 20, 100, 100)];
} completion:^(BOOL finished) {
// Animate moving to another location
}];
这是一个我想要的简单例子。我想要一个随机在屏幕上移动的图像。我想知道什么时候触球。
答
我偶然在一个不同的项目中遇到了答案。问题在于我试图找到视图的框架,因为它是动画。在动画过程中,帧不会改变。但有一个层的属性可以帮助。
[view.layer presentationLayer]
您可以从此图层属性中获取动画视图的当前帧。然后我可以用presentationLayers框架进行测试。