UIWindowTransition
UIWindowTransition is easy to use source for change UIWindow RootViewController with animation. UIWindowTransition written in Swift 4.0.
!!! ATTENTION !!! The documentation is not accurate because the sources are updated.
Requirements
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
- Create
Podfile
into your Xcode project. Open upTerminal
→cd
into your project's top-level directory → Run the following command:
$ pod init
- Open up created
Podfile
.
$ open Podfile
- In the
Podfile
that appears, specify. Instead of<Your Target Name>
, enter your project's name :
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘8.0’
target '<Your Target Name>' do
use_frameworks!
pod 'UIWindowTransition'
end
- Then, run the following command:
$ pod update
$ pod install
- Finally, open your Xcode
<Your Target Name>.xcworkspace
.
Manually
- Download
UIWindowTransition
and copy all files fromSource
folder into your project
Usage
- First of all you have to import
UIWindowTransition
import UIWindowTransition
- After that you need get UIWindow
// Window which need set root view controller.
// e.g.
let window = UIApplication.shared.windows.first
- Create Animation options if need
/*
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
- Set new root view controller
/*
controller - new rootViewController
transitionOptions - options for transition. If you put `nil`, viewController will change without animation
*/
window.setRootViewController(someController, transitionOptions: options)
License
Released under the MIT license. See LICENSE for details.