JTMaterialTransition
基于材料设计的 iOS 控制器过渡动画。
安装
使用 CocoaPods,在您的 Podfile 中添加此行。
pod 'JTMaterialTransition', '~> 2.0'
屏幕截图
用途
基本用法
import UIKit
import JTMaterialTransition
class ViewController: UIViewController {
weak var presentControllerButton: UIButton?
var transition: JTMaterialTransition?
override func viewDidLoad() {
super.viewDidLoad()
self.transition = JTMaterialTransition(animatedView: self.presentControllerButton)
}
func didPresentControllerButtonTouch () {
let controller = SecondViewController()
controller.modalPresentationStyle = .custom
controller.transitioningDelegate = self.transition
self.present(controller, animated: true, completion: nil)
}
}
注释
不直接使用animatedView
,根据动画的frame
、backgroundColor
属性创建一个新的视图。如果不提供视图,则需要设置startFrame
和startBackgroundColor
属性,并调用init
而不是initWithAnimatedView:
。
startFrame
必须是相对于窗口的坐标
var startFrame = animatedView.superview?.convert(animatedView.frame, to: nil)
警告
将要显示的控制器必须有一个backgroundColor
,否则效果可能会有点奇怪。如果你使用了一个UINavigationController
或其他容器,别忘了使用controllerPresented.view.backgroundColor = UIColor.yourColor
设置backgroundColor
。
要求
- iOS 8.0或更高版本
- Swift 4.2
作者
许可证
JTMaterialTransition是在MIT许可证下发布的。有关更多信息,请参阅LICENSE文件。