0
我發現下面列出的代碼從https://github.com/DuncanMC/iOS-CAAnimation-group-demo。這種特殊的方法允許用戶使用手勢識別器在覈心動畫序列中「在飛行中」時停止UIView。點擊視圖時,動畫停止。如圖所示,此代碼僅適用於動畫視圖。我有很多動畫視圖,我需要與任何視圖進行交互。我想我必須設置一系列視圖(或圖層)並循環瀏覽它們。它是否正確?我怎麼能這樣做?謝謝!如何設置手勢識別器在所有視圖都動畫時與任何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];
}
}
}
}