我在https://github.com/DuncanMC/iOS-CAAnimation-group-demo找到了下面列出的代码。该特定方法允许用户在使用手势识别器在核心动画序列中“飞行中”时停止UIView。点击视图时,动画停止。如图所示,此代码仅适用于动画视图。我有很多动画视图,我需要与任何视图进行交互。我想我必须建立一个视图(或层)数组并循环它们。它是否正确?我怎么能这样做?谢谢!
/*
This method gets called from a tap gesture recognizer installed on the view myContainerView.
We get the coordinates of the tap from the gesture recognizer and use it to hit-test
myContainerView.layer.presentationLayer to see if the user tapped on the moving image view's
(presentation) layer. The presentation layer's properties are updated as the animation runs, so hit-testing
the presentation layer lets you do tap and/or collision tests on the "in flight" animation.
*/
- (IBAction)testViewTapped:(id)sender
{
CALayer *tappedLayer;
id layerDelegate;
UITapGestureRecognizer *theTapper = (UITapGestureRecognizer *)sender;
CGPoint touchPoint = [theTapper locationInView: myContainerView];
if (animationInFlight)
{
tappedLayer = [myContainerView.layer.presentationLayer hitTest: touchPoint];
layerDelegate = [tappedLayer delegate];
if (((layerDelegate == imageOne && !doingMaskAnimation)) ||
(layerDelegate == waretoLogoLarge && doingMaskAnimation))
{
if (myContainerView.layer.speed == 0)
[self resumeLayer: myContainerView.layer];
else
{
[self pauseLayer: myContainerView.layer];
//Also kill all the pending label changes that we set up using performSelector:withObject:afterDelay
[NSObject cancelPreviousPerformRequestsWithTarget: animationStepLabel];
}
}
}
}
答案 0 :(得分:0)
LOL。那个演示项目是我的。编写代码是为了找到被挖掘的图层,然后使用这样一个事实:对于支持UIView的图层,图层的委托就是视图本身。
在代码中找到layerDelegate的位置,你应该确保它是KindOfClass UIView,然后使用任何适合的方法来匹配你的视图和你动画的视图。您可以使用IBOutletCollection来跟踪您正在制作动画的视图,或手动创建可变数组并向其添加视图对象,使用视图标记或对您的应用程序有意义的任何内容。