I want to add animation to a view while changing its hidden mode i.e
my_view.hidden=YES;
I have added a button in navigationbar. When we click on it the new view is set to be unhide. It draws at the upper of the navigation table.
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 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.
UIView. animate runs on the main thread and is asynchronous.
Animate the view's opacity from 100% to 0%. Have the animation completion callback set the view to be hidden. You might also want to reset the opacity back to 100% during the callback, so the view will display fully opaque when you unhide it.
yourView.alpha = 0.0 //for zero opacity yourView.alpha = 1.0 //for 100% opacity
There is no animation for hiding however; you get the same result with the Swift code below:
UIView.animate(withDuration: 0.2, delay: 0, options: [], animations: { self.yourView.alpha = 0 // Here you can change the alpha property of the view }, completion: { _ in self.yourView.isHidden = true // Here you hide it when animation done })
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