Hero README

The project's README from github.com/HeroTransitions/Hero. As one markdown file: README.md.

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 Accio supported codecov Version License Xcode 10.0+ iOS 10.0+ Swift 4.0+ 中文 README Donate

Unit Test Swift PM

      

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.

      

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

Usage Example 1

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

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!

Installation

CocoaPods

Add the following entry to your Podfile:

pod 'Hero'

Then run pod install.

Don't forget to import Hero in every file you'd like to use Hero.

Carthage

Add the following entry to your Cartfile:

github "HeroTransitions/Hero"

Then run carthage update.

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.

Accio

Add the following to your Package.swift:

.package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.4.0")),

Next, add Hero to your App targets dependencies like so:

.target(
    name: "App",
    dependencies: [
        "Hero",
    ]
),

Then run accio update.

Swift Package Manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.3.0"))

and then specify "Hero" as a dependency of the Target in which you wish to use Hero. Here's an example PackageDescription:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.6.3"))
    ],
    targets: [
        .target(
            name: "MyPackage",
            dependencies: ["Hero"])
    ]
)

Manually

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)

Dash compatible API docs: https://HeroTransitions.github.io/Hero/

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.

Hero (HeroTransitions/Hero)

Searching Database…

22.5K ·GitHub
这是做什么的?Hero 是一个用于构建 iOS 视图控制器转场动画的 Swift 库——它在 UIKit 那套繁琐的转场 API 之上提供了一层声明式封装,让自定义转场变得简单。
所以它不是一个应用——它怎么接入我的项目?它是一个库:你把它作为依赖添加到 Xcode 项目里,然后在每个需要声明或使用转场动画的文件中 import Hero。
我怎么把它加到我的项目里?有五种方式:CocoaPods(把 Hero 加进 Podfile,然后运行 pod install)、Carthage(写入 Cartfile,然后运行 carthage update)、Accio、Swift Package Manager,或者手动把 Sources 文件夹拖进项目。
它是独立的,还是会引入其他依赖?它是独立的:没有列出任何第三方依赖——只是 UIKit 之上的一层封装,所以你只需要一个 iOS 或 tvOS 的 Xcode 项目就行。
有什么需要注意的坑吗?在导航控制器里做 push/pop 时,必须同时在该导航控制器上开启 hero.isEnabled;另外 Hero 默认的 push 动画可能会和你的动画同时播放——把 navigationAnimationType 设为 .fade 或 .none 即可关掉它。
这些都必须写代码实现,还是可以在 storyboard 里设置转场?在 storyboard 里也可以做到——README 里的用法示例在代码和 storyboard 两种形式下都适用。
它在 iOS 之外能用吗——macOS、Android、网页端?不能——它只面向 iOS 和 tvOS。由于它封装的是 UIKit 的转场 API,所以只能用于苹果的手机和电视平台。
两个页面之间执行转场时,匹配视图是怎么工作的?想要延续到下一个页面的视图会在两个视图控制器之间进行匹配。匹配视图默认在全局坐标系里做动画,因此未匹配的、处于局部坐标系的视图可能会被盖住——给被盖住的视图加上 useGlobalCoordinateSpace 修饰符就能解决这个问题。
退出(dismiss)动画可以和弹出(present)动画不一样吗?可以——使用 .selectBy(presenting:dismissing) 这个动画类型,就可以为退出指定与弹出不同的默认动画。
Hero 还在维护吗?看起来维护得很健康:仓库没有归档,持续运行着构建、测试和 lint 的 CI 工作流,从 2016 年开发至今,在 GitHub 上已有 22k+ 星标。
Size
30.8 MB
Stars
22.5K
Age
9y
Commits · 90 Days