You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
7.4 KiB

6 years ago
  1. <img src="https://cdn.rawgit.com/lkzhao/Hero/427d5f2/Resources/Hero.svg" width="388"/>
  2. **Hero** is a library for building iOS view controller transitions. It provides a declarative layer on top of the UIKit's cumbersome transition APIs—making custom transitions an easy task for developers.
  3. [![Carthage compatible](https://img.shields.io/badge/Carthage-Compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)
  4. [![Version](https://img.shields.io/cocoapods/v/Hero.svg?style=flat)](http://cocoapods.org/pods/Hero)
  5. [![License](https://img.shields.io/cocoapods/l/Hero.svg?style=flat)](https://github.com/lkzhao/Hero/blob/master/LICENSE?raw=true)
  6. ![Xcode 9.0+](https://img.shields.io/badge/Xcode-9.0%2B-blue.svg)
  7. ![iOS 8.0+](https://img.shields.io/badge/iOS-8.0%2B-blue.svg)
  8. ![Swift 4.0+](https://img.shields.io/badge/Swift-4.0%2B-orange.svg)
  9. [![中文 README](https://img.shields.io/badge/%E4%B8%AD%E6%96%87-README-blue.svg?style=flat)](https://github.com/lkzhao/Hero/blob/master/README.zh-cn.md)
  10. [![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NT5F7Y2MPV7RE)
  11. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/features.svg"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  12. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/features2.svg"/>
  13. Hero is similar to Keynote's **Magic Move**. It checks the `heroID` property on all source and destination views. Every matched view pair is then automatically transitioned from its old state to its new state.
  14. Hero can also construct animations for unmatched views. It is easy to define these animations via the `heroModifiers` property. Hero will run these animations alongside the **Magic Move** animations. All of these animations can be **interactively controlled** by user gestures.
  15. At view controller level, Hero provides several template transitions that you can set through `heroModalAnimationType`, `heroNavigationAnimationType`, and `heroTabBarAnimationType`. These can be used as the foundation of your custom transitions. Combine with `heroID` & `heroModifiers` to make your own unique transitions.
  16. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/defaultAnimations.svg"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  17. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/defaultAnimations2.svg"/>
  18. By default, Hero provides **dynamic duration** based on the [Material Design Motion Guide](https://material.io/guidelines/motion/duration-easing.html). Duration is automatically determined by changes to distance and size—saving you the hassle, while providing consistent and delightful animations.
  19. Hero doesn't make any assumptions about how the view is built or structured. It won't modify any of your views' states other than hiding them during the animation. This makes it work with **Auto Layout**, **programmatic layout**, **UICollectionView** (without modifying its layout object), **UITableView**, **UINavigationController**, **UITabBarController**, etc...
  20. ## Example Gallery
  21. Checkout the [Example Gallery Blog Post](http://lkzhao.com/2016/12/28/hero.html) for a general idea of what you can achieve with **Hero**
  22. ## Usage Example 1
  23. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/simple.svg" />
  24. ##### View Controller 1
  25. ```swift
  26. redView.hero.id = "ironMan"
  27. blackView.hero.id = "batMan"
  28. ```
  29. ##### View Controller 2
  30. ```swift
  31. self.hero.isEnabled = true
  32. redView.hero.id = "ironMan"
  33. blackView.hero.id = "batMan"
  34. whiteView.hero.modifiers = [.translate(y:100)]
  35. ```
  36. ## Usage Example 2
  37. <img src="https://cdn.rawgit.com/lkzhao/Hero/ebb3f2c/Resources/advanced.svg" />
  38. ##### View Controller 1
  39. ```swift
  40. greyView.hero.id = "skyWalker"
  41. ```
  42. ##### View Controller 2
  43. ```swift
  44. self.hero.isEnabled = true
  45. greyView.hero.id = "skyWalker"
  46. // collectionView is the parent view of all red cells
  47. collectionView.hero.modifiers = [.cascade]
  48. for cell in redCells {
  49. cell.hero.modifiers = [.fade, .scale(0.5)]
  50. }
  51. ```
  52. You can do these in the **storyboard** too!
  53. <img src="https://cdn.rawgit.com/lkzhao/Hero/master/Resources/storyboardView.png" width="267px"/>
  54. <img src="https://cdn.rawgit.com/lkzhao/Hero/master/Resources/storyboardViewController.png" width="267px"/>
  55. ## Installation
  56. ### CocoaPods
  57. Add the following entry to your Podfile:
  58. ```rb
  59. pod 'Hero'
  60. ```
  61. Then run `pod install`.
  62. Don't forget to `import Hero` in every file you'd like to use Hero.
  63. ### Carthage
  64. Add the following entry to your `Cartfile`:
  65. ```
  66. github "HeroTransitions/Hero"
  67. ```
  68. Then run `carthage update`.
  69. If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained [over at Carthage](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).
  70. ### Swift Package Manager
  71. To integrate using Apple's Swift package manager, add the following as a dependency to your `Package.swift`:
  72. ```swift
  73. .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.3.0"))
  74. ```
  75. and then specify `"Hero"` as a dependency of the Target in which you wish to use Hero.
  76. Here's an example `PackageDescription`:
  77. ```swift
  78. // swift-tools-version:4.0
  79. import PackageDescription
  80. let package = Package(
  81. name: "MyPackage",
  82. products: [
  83. .library(
  84. name: "MyPackage",
  85. targets: ["MyPackage"]),
  86. ],
  87. dependencies: [
  88. .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.3.0"))
  89. ],
  90. targets: [
  91. .target(
  92. name: "MyPackage",
  93. dependencies: ["Hero"])
  94. ]
  95. )
  96. ```
  97. ### Manually
  98. - Drag the **Sources** folder anywhere in your project.
  99. ## Documentations
  100. Checkout the **[WIKI PAGES (Usage Guide)](https://github.com/lkzhao/Hero/wiki/Usage-Guide)** for documentations.
  101. For more up-to-date ones, please see the header-doc. (use **alt+click** in Xcode)
  102. <img src="https://cdn.rawgit.com/lkzhao/Hero/master/Resources/headerDoc.png" width="521px"/>
  103. ## Interactive Transition Tutorials
  104. [Interactive transitions with Hero (Part 1)](http://lkzhao.com/2017/02/05/hero-interactive-transition.html)
  105. ## FAQ
  106. #### Not able to use Hero transition even when `self.hero.isEnabled` is set to true
  107. Make sure that you have also enabled `self.hero.isEnabled` on the navigation controller if you are doing a push/pop inside the navigation controller.
  108. #### Views being covered by another matched view during the transition
  109. Matched views use global coordinate space while unmatched views use local coordinate space by default. Local coordinate spaced views might be covered by other global coordinate spaced views. To solve this, use the `useGlobalCoordinateSpace` modifier on the views being covered. Checkout [Coordinate Space Wiki page](https://github.com/lkzhao/Hero/wiki/Coordinate-Space) for details.
  110. #### Push animation is shown along side my custom animation
  111. This is the default animation for navigation controller provided by Hero. To disable the push animation, set `self.hero.navigationAnimationType` to `.fade` or `.none` on the navigation controller.
  112. #### How do I use a different default animation when dismissing
  113. You can use the animation type `.selectBy(presenting:dismissing)` to specify a different default animation for dismiss.
  114. For example:
  115. ```swift
  116. self.hero.modalAnimationType = .selectBy(presenting:.zoom, dismissing:.zoomOut)
  117. ```
  118. ## Contribute
  119. We welcome any contributions. Please read the [Contribution Guide](https://github.com/lkzhao/Hero/wiki/Contribution-Guide).