Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView appereance from bottom to top and vice versa(Core Animation)

Tags:

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.


Visual implementation

So what exactly i want to do(few steps as shown on images):
1. Source
2. enter image description here
3. enter image description here
4. enter image description here

And the same steps to hide view(vice versa,from top to bottom) until this :

enter image description here

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!

like image 607
XTL Avatar asked Feb 19 '17 11:02

XTL


People also ask

How does UIView animate work?

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.

Does UIView animate run on the main thread?

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.

Does UIView animate need weak self?

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.

How to animate a UIView in Swift?

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.

How to move a view from bottom to top in Swift?

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.

How to move UIView from left to right with SWIFT code?

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.


Video Answer


1 Answers

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             })     } } 
like image 65
Gowtham Sooryaraj Avatar answered Oct 25 '22 10:10

Gowtham Sooryaraj