UIWindowTransition
UIWindowTransition 是一个易于使用、用于通过动画更改 UIWindow RootViewController 的 Swift 4.0 源代码。
!!! 注意 !!! 由于源代码已更新,文档可能不准确。
需求
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
安装
CocoaPods
CocoaPods 是一个用于 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:
$ gem install cocoapods
- 在您的 Xcode 项目中创建
Podfile
。打开终端
→cd
进入您的项目的顶级目录 → 运行以下命令:
$ pod init
- 打开创建的
Podfile
。
$ open Podfile
- 在出现的
Podfile
中,指定。请用<Your Target Name>
代替您的项目名称
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘8.0’
target '<Your Target Name>' do
use_frameworks!
pod 'UIWindowTransition'
end
- 然后,运行以下命令:
$ pod update
$ pod install
- 最后,打开您的 Xcode
<Your Target Name>.xcworkspace
。
手动
- 下载
UIWindowTransition
并将Source
文件夹中的所有文件复制到您的项目中
用法
- 首先您需要导入
UIWindowTransition
import UIWindowTransition
- 然后您需要获取 UIWindow
// Window which need set root view controller.
// e.g.
let window = UIApplication.shared.windows.first
- 如果需要,创建动画选项
/*
Animation for UIWindow transition:
- Fade: center -> center (animated change alpha)
- zoom(scale): center -> center (scale from `scale` to 1.0)
- toTop: bottom -> top
- toBottom: top -> bottom
- toLeft: right -> left
- toRight: left -> right
*/
let animation: UIWindowTransitionOptions.Transition
// You can create options if you would like animated set root view controller.
var options = UIWindowTransitionOptions(transition: animation)
options.duration = 0.4 // Set custom duration in seconds if need. Default is 0.25s
options.curve = .easeIn // Set custom curve if need. Default is linear
- 设置新的根视图控制器
/*
controller - new rootViewController
transitionOptions - options for transition. If you put `nil`, viewController will change without animation
*/
window.setRootViewController(someController, transitionOptions: options)
许可
遵循MIT许可发布。有关详情,请参阅LICENSE