In this blog we will know how we can use Hero Library in swift
- Please create a new project or you can use this in the existing product in which you want to implement Hero Library
2. Then you need to add pod in the project
1 |
pod 'Hero' |
3. Then you need to import the library in the controller
1 |
import Hero |
4. You need to create a new view controller to check the presentation style of the view controller
Please enter the below code in you controller in which you need to use it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
var animations: [HeroDefaultAnimationType] = [ .push(direction: .left), .pull(direction: .left), .slide(direction: .leading), .zoomSlide(direction: .trailing), .cover(direction: .up), .uncover(direction: .up), .pageIn(direction: .left), .pageOut(direction: .left), .fade, .zoom, .zoomOut, .none ] |
These are the herolibrary default style
By using this you can present the view controller with different style
5. Please put the below code to your action or button click to present the new view controller
1 2 3 4 5 |
if let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController{ present(vc, animated: true, completion: nil) } |
in the above line of code you will simply present the new view controller
please use this line of code to present is with some style
1 2 3 4 5 6 7 |
if let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController{ vc.modalPresentationStyle = .fullScreen vc.hero.isEnabled = true vc.hero.modalAnimationType = animations[Int.random(in: 1..<11)] present(vc, animated: true, completion: nil) } |
In the above gif you can see the animation from first controller to another one
Thanks for reading
Hope this blog helped you with a better understanding of Hero Library.
For more technical blogs please visit here.
For more detail about the hero library please click here
If you have any queries/doubt please comment