I want to trigger a CAAnimation with a Button. In playground and in the simulator, this works exactly as I want it to. However, when I run the same code on a device, the animation happens only after a short delay.
Apparently, the issue only happens on iOS 11.2.6. I updated my device and can now not reproduce the issue anymore. Can anyone confirm, or find out, how it would work on iOS 11.2.6?
import UIKit class MyViewController : UIViewController { let animatedView = UIView() override func loadView() { let view = UIView() view.backgroundColor = .white // Add a button let button = UIButton(type: .system) button.frame = CGRect(x: 150, y: 200, width: 200, height: 50) button.setTitle("Animate", for: .normal) button.addTarget(self, action: #selector(tap), for: .touchUpInside) // Set color and frame of the view, that is animated. animatedView.backgroundColor = UIColor.blue animatedView.frame = CGRect(x: 50, y: 50, width: 50, height: 50) // Add the views to the view hierarchy view.addSubview(animatedView) view.addSubview(button) self.view = view } /// On Tap create an animation, that changes the position of the animated view. @objc func tap() { let originalY = animatedView.layer.position.y let animation = CABasicAnimation(keyPath: "position.y") animation.fromValue = originalY animation.toValue = 300.0 animation.duration = 1.0 animatedView.layer.add(animation, forKey: "positionAnimation") } } 1 Answers
Answers 1
I have tested your code in 6s+ with 11.2.6 but not getting delay... also working fine with other versions.
Maybe something going wrong with a specific device as based on device specification.
0 comments:
Post a Comment