@IBOutlet weak var imageView: UIImageView!
override func viewWillAppear(animated: Bool) {
self.imageView.center.y -= view.bounds.height
}
override func viewDidAppear(animated: Bool) {
UIView.animateWithDuration(0.5, delay: 0.3, options: nil, animations: {
self.imageView.center.y += self.view.bounds.height
}, completion: nil)
}
This code does successfully move the image view across the screen, but I'm not sure how to make it stop where I want it to. It just slides off the screen. The goal is to move the image from point A to point B. If there is another easier way to do this I would be happy to know. Thanks!
For this line:
self.imageView.center.y += self.view.bounds.height
Maybe make it move less?
self.imageView.center.y += self.view.bounds.height - 200
Your implementation is fine, you just have to understand the amount you are changing
y
by.self.view.bounds.height
refers to the height of the view controllers view. That's probably pretty big, in fact, likely the entire height of the screen you're looking at. So you need to decide what point you want to move it to and do some math. Say you want to stop it when it hits the top edge of the screen. You might do something very simple like:I did not test this, please implement in the way that works best for your situation.
Save original point and go!
Add this in viewWillAppear,you will get your animation,you problem is autoLayout
When you move a view frame,it is better use animate antoLayout Constraint
Drag the red Constraint into outlet then Example Code
Just moving it too far, that'll put the center in the middle of the screen.