2017-01-27 31 views
-1
  1. 我有圖,該旋轉是這樣的:CABasicAnimation上的UIView,兒童按鈕無法點擊

    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) 
    } 
    
  2. 有在此視圖中的多個小按鈕。

  3. 雖然父視圖正在旋轉並嘗試點按按鈕,但我無法點擊並且相應的操作方法未被調用。

請幫忙解決這個問題。

+0

[用CAAnimation支持的用戶交互?]的可能重複(http://stackoverflow.com/questions/11110485/user-interaction-enabled-with-caanimation) – Carter

+0

該帖子中給出的鏈接無效。任何幫助? –

+0

工作鏈接在這裏:http://ronnqvi.st/hit-testing-animating-layers/。未來,請在嘗試之前嘗試使用Google搜索,這是使用Google搜索時的第一個搜索結果。 – Carter

回答

0

當您爲視圖或圖層設置動畫時,實際視圖不會在動畫的中間位置移動。相反,視圖對象跳轉到動畫開始處的最終位置。 (動畫實際上發生在位於視圖正常圖層頂層的「表示層」上。)

如果您希望能夠點擊動畫中的「正在播放」按鈕,您將必須對視圖的表示層進行命中測試,並且不能使用按鈕來響應使用目標/操作的觸摸。

我在Github上有一個示例項目,演示瞭如果感興趣的話,可以在機上視圖中檢測水龍頭。看看Github上的https://github.com/DuncanMC/iOS-CAAnimation-group-demo。它是用Objective-C編寫的,但想法相同

+0

嗨鄧肯,請提供示例項目,因爲我試圖修復我的代碼,但它不工作。 –

+0

請參閱編輯我的答案。 –