Skip to content
项目

HeroTransitions/Hero has 22,494 GitHub stars and 1,721 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-08 08:27 UTC. Last push 2025-01-23.

这些数字如何统计

适用于 iOS 和 tvOS 的优雅转场库

实测星标增长

24小时
0
7天
更新延迟
15天
更新延迟
1个月
更新延迟

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.zh-cn.md

原文

Carthage compatible Version License Xcode 8.2+ iOS 8.0+ Swift 3.0+

Hero是一个iOS界面切换库。它代替了UIKit本身的转场动画接口,使制作自定义的转场动画(View Controller Transition)非常简单!

特点

      

你可以使用这些效果来拼凑出你想要的转场动画。

Hero很像Keynote的“神奇移动”过渡(Magic Move)。在界面切换时,Hero会把开始界面的视图与结束界面的视图配对,假如他能找到一对儿有着一样的heroID的视图的话,Hero便会自动为此视图创建动画,从它一开始的状态移动到结束时的状态。

不仅如此,Hero还可以为没有配对的视图制作动画。每一个视图都可以轻易的用heroModifiers来告诉Hero你想为这个视图所创造的动画。交互式动画(interactive transition)也是支持的哟。

Hero还参照Google的Material Design Motion Guide来提供动态的动画长度。你不需要告诉Hero动画时间,Hero会参照视图的移动长度和大小来自动选择最适合的参数。

无论你使用怎样的方法制作和布局你的视图,Hero都能帮你省去很多时间制作动画。Hero支持 auto layout, programmatic layout, UICollectionView, UITableView, UINavigationController, UITabBarController, 等等。。

还有

从0.3.0开始. Hero自带许多转场动画. 这些自带的转场动画可以与你的heroID & heroModifiers结合,搭配出简单却又独一无二的动画。

      

效果

请看Example Gallery Blog Post来了解Hero具体能做出什么样的效果

安装方法与用法

Hero可以用Carthage或者Cocoapods安装,具体用法请见**Usage Guide**。

注: 因为一个苹果的bug,Hero 不能在iPhone 7 Simulators上使用。 请使用其他版本的Simulator或者使用真机。

简单实例 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)]

简单实例 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)]
}

Hero 还支持 storyboard。 你可以在Storyboard右边的Identity Inspector来使用HeroID与HeroModifiers。

Contribute

We welcome any contributions. Please read the Contribution Guide.

License

Hero is available under the MIT license. See the LICENSE file for more info.

探索相关项目