ImageTransition
ImageTransition 是一个库,用于在过渡期间对图像进行平滑动画。
下面是一个示例
例如 UIImageView | 例如 UICollectionView 中的 UIImageView |
---|---|
![]() |
![]() |
特点
- 过渡缩放动画,类似于 iOS Photos 应用程序和 "Pinterest" 等
- 易于使用(遵守
ImageTransitionable
协议) - Swift(基于协议的)
- 动画配置可定制(动画持续时间,UIView.AnimationOptions)
- 圆角动画(例如,从圆形图片到方形图片)
安装
Carthage
- 将
github "shtnkgm/ImageTransition"
添加到您的 Cartfile 中。 - 运行 carthage update。
CocoaPods
- 将
pod 'ImageTransition'
添加到您的 Podfile。 - 运行 pod update。
使用方法
- 确认
ImageTransitionable
协议
// Source UIViewController
import ImageTransition
extension SourceViewController: ImageTransitionable {
var imageViewForTransition: UIImageView? {
return imageView
}
}
// Destination UIViewController
import ImageTransition
extension DestinationViewController: ImageTransitionable {
var imageViewForTransition: UIImageView? {
return imageView
}
}
- 设置代理
// present / dismiss transition
@objc private func imageViewDidTapped() {
let destinationViewController = DestinationViewController.make()
destinationViewController.transitioningDelegate = ImageTransitionDelegate.shared
present(destinationViewController, animated: true, completion: nil)
}
// push / pop transition
@objc private func imageViewDidTapped() {
let destinationViewController = DestinationViewController.make()
// Set ImageTransitionDelegate.shared to `delegate` property of UINavigationContoller
navigationController?.delegate = ImageTransitionDelegate.shared
navigationController?.pushViewController(destinationViewController, animated: true)
}
自定义
您可以自定义动画配置。
ImageTransitionDelegate.shared.presentDuration = 0.5
ImageTransitionDelegate.shared.dismissDuration = 0.5
ImageTransitionDelegate.shared.pushDuration = 0.5
ImageTransitionDelegate.shared.popDuration = 0.5
ImageTransitionDelegate.shared.presentAnimationOptions = [.curveLinear]
ImageTransitionDelegate.shared.dismissAnimationOptions = [.curveEaseIn]
ImageTransitionDelegate.shared.pushAnimationOptions = [.curveLinear]
ImageTransitionDelegate.shared.popAnimationOptions = [.curveEaseIn]
要求
- iOS 12.0 或更高版本
贡献
欢迎提交 Pull requests 和 stars。
对于 bug 和功能请求,请创建一个问题。
- 分支它!
- 创建您的功能分支:git checkout -b my-new-feature
- 提交您的更改:git commit -am '添加某些功能'
- 推送分支:git push origin my-new-feature
- 提交 pull request :D
作者
- @shtnkgm / Shota Nakagami
许可证
ImageTransition 采用 MIT 许可证发布。有关详细信息,请参阅 LICENSE。