User Interaction Enabled With CAAnimation?

后端 未结 2 1000
春和景丽
春和景丽 2021-01-22 16:29

It is very easy to allow users to interact with views while animating using the options field of block based animation. But in my program I am using a CAKeyframeAnimation and I

2条回答
  •  心在旅途
    2021-01-22 16:56

    Apparently, preview solution no longer works in Swift 3.x and Swift 4.x

    I solved the issue setting a Timer to update the frame during the animation.

    //Timer: To update the UI frame
        Timer.scheduledTimer(timeInterval: 0.15, target: self, selector: #selector(updateFrame), userInfo: nil, repeats: true)
    
    //Timer Selector
    @objc func updateFrame(){
       //getting the layer presentation bounds
        let layer = "button, label...".layer.presentation()!
    
        let point = CGPoint(x: layer.frame.origin.x, y: layer.frame.origin.y)
        let size = CGSize(width: layer.frame.width, height: layer.frame.height)
        // Update the UI element frame location
        "ui element".frame = CGRect(origin: point, size: size)
    }
    

提交回复
热议问题