I have taken image and I want flyView to be drop from top middle to 200 from top and vanishes. for that tried like this
code: here I have given constraints for flyView as flyView.centerXAnchor and flyView.topAnchor then why flyView coming inside from left of the screen?? and when animation happening then why whole screen moves badly. i have clear tableview and below submit button as well but whole screen moving with animation why? how to fix this? please guide me.
class TableAnimationViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
let flyView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
self.flyView.image = UIImage(named: "offer_img")
self.view.addSubview(flyView)
self.flyView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
flyView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 50),
flyView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
flyView.widthAnchor.constraint(equalToConstant: 100),
flyView.heightAnchor.constraint(equalToConstant: 100)
])
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIView.animate(withDuration: 5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: [.curveEaseOut, .repeat], animations: { [self] in
flyView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 200).isActive = true
flyView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
flyView.alpha = 0
self.view.layoutIfNeeded()
})
}
}
o/p

