My goal is to understand and implement feature via Core Animation.
I think it's not so hard,but unfortunately i don't know swift/Obj C and it's hard to understand native examples.
So what exactly i want to do(few steps as shown on images):
1.
2.
3.
4.
And the same steps to hide view(vice versa,from top to bottom) until this :
Also,i want to make this UIView more generic,i mean to put this UIView on my StoryBoard and put so constraints on AutoLayout(to support different device screens).
Any ideas? Thanks!
it queries the views objects for changed state and gets back the initial and target values and hence knows what properties to change and in what range to perform the changes. it calculates the intermediate frames, based on the duration and initial/target values, and fires the animation.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] . It's best to let the OS run your animations; the animation thread does not block the main thread -- only the animation block itself.
You don't need to use [weak self] in static function UIView. animate() You need to use weak when retain cycle is possible and animations block is not retained by self.
The swift UIView’s animate method provides animation effect for your UIView instance, what you need to do is just pass different parameters to the function.
The third button ( button text is Bottom To Top UIView Animation ) implements a uiview animation from bottom to top in swift code. When you click the third button, it will first move the view to the bottom, then move the view object to the screen top with animation.
The second button ( button text is Left To Right UIView Animation ) implements a uiview animation move from left to right with swift code. When you click the second button, the red uiview object will first move to the screen left side, then it will move from left to right smoothly.
You can use like this Extension
extension UIView{ func animShow(){ UIView.animate(withDuration: 2, delay: 0, options: [.curveEaseIn], animations: { self.center.y -= self.bounds.height self.layoutIfNeeded() }, completion: nil) self.isHidden = false } func animHide(){ UIView.animate(withDuration: 2, delay: 0, options: [.curveLinear], animations: { self.center.y += self.bounds.height self.layoutIfNeeded() }, completion: {(_ completed: Bool) -> Void in self.isHidden = true }) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With