SweetBubblesTransition
SweetBubblesTransition 是一个使用 swift 编写的转场效果,基于添加子控制器。它是一个甜蜜的动画,给予用户意想不到的体验。气泡使你的生活更美好!
安装
SweetBubblesTransition 通过 CocoaPods 提供。要在 Xcode 中使用 Cocoapods 集成 SweetBubblesTransition,请在 Podfile 中指定它
pod 'SweetBubblesTransition'
用法
此转场使用了由 AliSoftware 创建的可复用库。
实际上,为了理解它,我们将进行叠加。
从您的第一个 ViewController,我们将添加想转场到的 ViewController(称为 VC2),并在其上方添加 BubbleViewController(这将生成转场效果)。
最后,使 VC2 可见并移除 BubbleVC。这就是全部!
为此我们使用了 StoryBased 方法,让我们来看看流程
-
首先,让我们假设您刚刚创建了项目,因此您有 Mainstoryboard 和默认的一个 ViewController。我们将将其称为 VC1 以供后续解释。
-
创建一个名为 ViewController2 的新 Storyboard(例如),并添加一个名字相同的新 ViewController(非常重要)ViewController2。现在我们有了 VC2,别忘了添加一个自己的类
// We have to import Reusable
import UIKit
import Reusable
// And add to it the StoryboardBased protocol
class ViewController2: UIViewController, StoryboardBased {
}
- 这就是 VC2 的全部内容!现在转到 VC1 Swift 文件并执行以下操作
// Now we can add here SweetBubblesTransition
import UIKit
import SweetBubblesTransition
// Change your VC1's type by AnimationController
class ViewController: AnimationController {
// You have to instantiate your VC2 by using the method .instantiate() (thanks again to Reusable).
private let viewController2 = ViewController2.instantiate()
// Now for this exemple I just create a button on the VC1, and assign it the following function
@IBAction func change(_ sender: Any) {
// ------------------------------- PARAMETERS INDICATIONS -------------------------------
// 1. 'to' means the VC you want to transition to
// 2. 'animation' is the time of the transition. If you choose 2, for exemple, that means the VC2 will appear in two seconds.
// 3. 'bubbleController' is the time you want to remove the BubbleViewController
// Personnally I think 3sec for the animation and 2.5sec to delete the BubbleVC is the perfect timing, but feel free to make your own opinion !
startTransition(to: viewController2, animation: 3, bubbleController: 2.5)
}
}
- 享受吧!
需求
- 针对 iOS 10.0+ 的目标部署
- Swift 5
通信
- 如果您需要帮助,请打开一个问题。
- 如果您发现了一个错误,请打开一个问题。
- 如果您有特性请求,请打开一个问题。
作者
Lucas Amelin, [email protected]
许可
此代码基于MIT许可证分发。有关更多信息,请参阅许可文件。