[英]CABasicAnimation on UIView, Child button is not clickable
我有這樣旋轉的視圖:
if view.layer.animation(forKey: kRotationAnimationKey) == nil { let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation") rotationAnimation.fromValue = 0.0 rotationAnimation.toValue = Float(M_PI * 2.0) rotationAnimation.duration = duration rotationAnimation.repeatCount = Float.infinity view.layer.add(rotationAnimation, forKey: kRotationAnimationKey) }
此視圖上有多個小按鈕。
當父視圖正在旋轉並嘗試點擊按鈕時,我無法點擊並且沒有調用相應的操作方法。
請幫助解決這個問題。
當您為視圖或圖層設置動畫時,實際視圖不會通過動畫的中間位置移動。 相反,視圖對象會在動畫開始時跳轉到它的最終位置。 (動畫實際上發生在“表示層”上,該層位於視圖的正常層層次結構之上。)
如果您希望能夠點擊動畫中“飛行中”的按鈕,您必須在視圖的表示層上進行點擊測試,並且您不能讓按鈕響應使用目標/動作的觸摸。
如果您有興趣,我在 Github 上有一個示例項目,它演示了在飛行視圖上檢測點擊。 看看 Github 上的https://github.com/DuncanMC/iOS-CAAnimation-group-demo 。 它是用Objective-C編寫的,但思想是一樣的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.