Middle+
How to get the current frame value when making changes to animations at a specific second?
sobes.tech AI
Answer from AI
Using the presentationLayer of the layer.
import QuartzCore
let myView: UIView // Assume this is an animatable view
// Get the presentation layer
if let presentationLayer = myView.layer.presentation() {
// Extract the frame from the presentation layer
let currentAnimatedFrame = presentationLayer.frame
// Use currentAnimatedFrame for further operations
print("Current animated frame: \(currentAnimatedFrame)")
} else {
// If the presentation layer is not available (e.g., animation not running)
let currentFrame = myView.frame
print("Animation not running, using current frame: \(currentFrame)")
}
The presentationLayer reflects the actual position and state of a property at the current moment during animation execution, whereas the main layer (layer or modelLayer) contains the final value of the property after the animation completes.