87

GitHub - lkzhao/Hero: Elegant transition library for iOS & tvOS

 6 years ago
source link: https://github.com/lkzhao/Hero
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

README.md

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f343237643566322f5265736f75726365732f4865726f2e737667

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.

Carthage compatible Version License Xcode 9.0+ iOS 8.0+ Swift 4.0+ 中文 README Donate

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f66656174757265732e737667       68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f6665617475726573322e737667

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.

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.

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.

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f64656661756c74416e696d6174696f6e732e737667       68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f64656661756c74416e696d6174696f6e73322e737667

By default, Hero provides dynamic duration based on the Material Design Motion Guide. Duration is automatically determined by changes to distance and size—saving you the hassle, while providing consistent and delightful animations.

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...

Example Gallery

Checkout the Example Gallery Blog Post for a general idea of what you can achieve with Hero

Usage Example 1

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f73696d706c652e737667

View Controller 1
redView.hero.id = "ironMan"
blackView.hero.id = "batMan"
View Controller 2
self.hero.isEnabled = true
redView.hero.id = "ironMan"
blackView.hero.id = "batMan"
whiteView.hero.modifiers = [.translate(y:100)]

Usage Example 2

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f656262336632632f5265736f75726365732f616476616e6365642e737667

View Controller 1
greyView.hero.id = "skyWalker"
View Controller 2
self.hero.isEnabled = true
greyView.hero.id = "skyWalker"

// collectionView is the parent view of all red cells
collectionView.hero.modifiers = [.cascade]
for cell in redCells {
	cell.hero.modifiers = [.fade, .scale(0.5)]
}

You can do these in the storyboard too!

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f6d61737465722f5265736f75726365732f73746f7279626f617264566965772e706e67

68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f6d61737465722f5265736f75726365732f73746f7279626f61726456696577436f6e74726f6c6c65722e706e67

Documentations

Checkout the WIKI PAGES (Usage Guide) for documentations.

For more up-to-date ones, please see the header-doc. (use alt+click in Xcode) 68747470733a2f2f63646e2e7261776769742e636f6d2f6c6b7a68616f2f4865726f2f6d61737465722f5265736f75726365732f686561646572446f632e706e67

Interactive Transition Tutorials

Interactive transitions with Hero (Part 1)

FAQ

Not able to use Hero transition even when self.hero.isEnabled is set to true

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.

Views being covered by another matched view during the transition

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 for details.

Push animation is shown along side my custom animation

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.

How do I use a different default animation when dismissing

You can use the animation type .selectBy(presenting:dismissing) to specify a different default animation for dismiss.

For example:

    self.hero.modalAnimationType = .selectBy(presenting:.zoom, dismissing:.zoomOut)

Contribute

We welcome any contributions. Please read the Contribution Guide.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK