I need to present an animation after the my view controller with the picture view is opened. I exploit this code for to do it, however the animation would not work in my app:
view controller
class ViewController: UIViewController {
lazy var button: UIButton = {
let button = UIButton()
button.backgroundColor = .darkGray
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, motion: #selector(present), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
tremendous.viewDidLoad()
view.addSubview(button)
button.body = CGRect(x: 500, y: 200, width: 100, peak: 100)
}
@objc func present() {
let detailController = OnboardingController()
self.current(detailController, animated: true, completion: nil)
}
}
OnboardingController code:
class OnboardingController: UIViewController {
non-public let imageView: UIImageView = {
let picture = UIImageView()
picture.picture = UIImage(named: "1")
picture.translatesAutoresizingMaskIntoConstraints = false
return picture
}()
override func viewDidLoad() {
tremendous.viewDidLoad()
view.addSubview(imageView)
imageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, fixed: -320).isActive = true
imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor, fixed: 0).isActive = true
imageView.layer.removeAllAnimations()
imageView.remodel = CGAffineTransformTranslate(.id, 0, 0)
UIView.animate(withDuration: 1.0, delay: 0, animations: {
self.imageView.remodel = CGAffineTransformTranslate(.id, 320, 0)
}, completion: nil)
}
}
How you can resolve this drawback?