|
5 | 5 | [](http://cocoapods.org/pods/AnimationSwitchRootViewController) |
6 | 6 | [](https://github.com/ProVir/AnimationSwitchRootViewController/blob/master/LICENSE) |
7 | 7 |
|
8 | | -Extension for UIWindow - animation switch rootViewController in UIWindow. |
| 8 | +Extension for UIWindow - animation switch rootViewController in UIWindow. Support Objective-C, Swift 3 and 4. |
| 9 | +If you need pure Objective-C, use AnimationSwitchRootViewControllerObjC. |
| 10 | + |
| 11 | +[Example demo](https://github.com/ProVir/AnimationSwitchRootViewController/blob/master/demo.gif) |
| 12 | + |
| 13 | + |
| 14 | +- [Features](#features) |
| 15 | +- [Requirements](#requirements) |
| 16 | +- [Communication](#communication) |
| 17 | +- [Installation](#installation) |
| 18 | +- [Usage](#usage) |
| 19 | +- [Author](#author) |
| 20 | +- [License](#license) |
| 21 | + |
| 22 | + |
| 23 | +## Features |
| 24 | + |
| 25 | +- [x] Change rootViewController in UIWindow with animation. |
| 26 | +- [x] Get main UIWindow from UIApplication static function sharedWindow(). |
| 27 | +- [x] Support CATransaction with backgrounds color, UIVIew or UIImage. |
| 28 | +- [x] Support animation move snapshots (manually). |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +## Requirements |
| 33 | + |
| 34 | +- iOS 8.0+ |
| 35 | +- Xcode 8.1, 8.2, 8.3, and 9.0 |
| 36 | +- Swift 3.0, 3.1, 3.2, and 4.0 |
| 37 | + |
| 38 | + |
| 39 | +## Communication |
| 40 | + |
| 41 | +- If you **need help**, go to [provir.ru](http://provir.ru) |
| 42 | +- If you **found a bug**, open an issue. |
| 43 | +- If you **have a feature request**, open an issue. |
| 44 | +- If you **want to contribute**, submit a pull request. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +### CocoaPods |
| 51 | + |
| 52 | +[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command: |
| 53 | + |
| 54 | +```bash |
| 55 | +$ gem install cocoapods |
| 56 | +``` |
| 57 | + |
| 58 | +> CocoaPods 1.1.0+ is required to build AnimationSwitchRootViewController 1.0.0+. |
| 59 | +
|
| 60 | +To integrate WebServiceSwift into your Xcode project using CocoaPods, specify it in your `Podfile`: |
| 61 | + |
| 62 | +```ruby |
| 63 | +source 'https://github.com/CocoaPods/Specs.git' |
| 64 | +platform :ios, '8.0' |
| 65 | +use_frameworks! |
| 66 | + |
| 67 | +target '<Your Target Name>' do |
| 68 | +pod 'AnimationSwitchRootViewController', '~> 1.0' |
| 69 | +end |
| 70 | +``` |
| 71 | + |
| 72 | +Then, run the following command: |
| 73 | + |
| 74 | +```bash |
| 75 | +$ pod install |
| 76 | +``` |
| 77 | + |
| 78 | +if you need pure Objective-C, use AnimationSwitchRootViewControllerObjC: |
| 79 | +```ruby |
| 80 | +pod 'AnimationSwitchRootViewControllerObjC', '~> 1.0' |
| 81 | +``` |
| 82 | + |
| 83 | +### Carthage |
| 84 | + |
| 85 | +[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. |
| 86 | + |
| 87 | +You can install Carthage with [Homebrew](http://brew.sh/) using the following command: |
| 88 | + |
| 89 | +```bash |
| 90 | +$ brew update |
| 91 | +$ brew install carthage |
| 92 | +``` |
| 93 | + |
| 94 | +To integrate AnimationSwitchRootViewController into your Xcode project using Carthage, specify it in your `Cartfile`: |
| 95 | + |
| 96 | +```ogdl |
| 97 | +github "ProVir/AnimationSwitchRootViewController" ~> 1.0 |
| 98 | +``` |
| 99 | + |
| 100 | +Run `carthage update` to build the framework and drag the built `AnimationSwitchRootViewController.framework` into your Xcode project. |
| 101 | + |
| 102 | +if you need pure Objective-C, use AnimationSwitchRootViewControllerObjC - drag the built `AnimationSwitchRootViewControllerObjC.framework` into your Xcode project. |
| 103 | + |
| 104 | + |
| 105 | +### Manually |
| 106 | + |
| 107 | +If you prefer not to use any of the aforementioned dependency managers, you can integrate AnimationSwitchRootViewController into your project manually. |
| 108 | + |
| 109 | +Copy files from directory `AnimationSwitchRootViewController` in your project. |
| 110 | +if you need pure Objective-C, don't copy `*.swift` files. |
| 111 | + |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Usage |
| 116 | + |
| 117 | +#### Interface in Swift (also Objective-C support): |
| 118 | +```swift |
| 119 | +public extension UIApplication { |
| 120 | + @objc public static func sharedWindow() -> UIWindow? |
| 121 | +} |
| 122 | + |
| 123 | +public extension UIWindow { |
| 124 | + |
| 125 | + ///Transition Direction - equal CATransitionSubType. |
| 126 | + @objc public enum TransitionDirection : Int { |
| 127 | + case fromRight |
| 128 | + case fromLeft |
| 129 | + case fromTop |
| 130 | + case fromBottom |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + Core Animation: custom transition and temp background window. |
| 135 | +
|
| 136 | + - Parameters: |
| 137 | + - rootViewController: ViewController to switch. |
| 138 | + - transition: Custom core animation transition. |
| 139 | + - backgroundColor: Background color when animation in process. Default is black. |
| 140 | + - backgroundView: View for background when animation in process. |
| 141 | + */ |
| 142 | + @objc public func switchRootViewController(to rootViewController: UIViewController, |
| 143 | + withTransition transition: CATransition, |
| 144 | + backgroundColor: UIColor? = nil, |
| 145 | + backgroundView: UIView? = nil) |
| 146 | + |
| 147 | + |
| 148 | + /** |
| 149 | + Core Animation: push transition and temp background window. |
| 150 | +
|
| 151 | + - Parameters: |
| 152 | + - rootViewController: ViewController to switch. |
| 153 | + - direction: Direction animation. Equal CATransitionSubType in CATransition. |
| 154 | + - duration: Duration animation. Default = 0.3. |
| 155 | + - backgroundColor: Background color when animation in process. Default is black. |
| 156 | + - backgroundView: View for background when animation in process. |
| 157 | + */ |
| 158 | + @objc public func switchRootViewControllerPushTransition(to rootViewController: UIViewController, |
| 159 | + direction: TransitionDirection, |
| 160 | + duration: CGFloat = 0.3, |
| 161 | + backgroundColor: UIColor? = nil, |
| 162 | + backgroundView: UIView? = nil) |
| 163 | + |
| 164 | + /** |
| 165 | + Core Animation: push transition and temp background window with image as background. |
| 166 | +
|
| 167 | + - Parameters: |
| 168 | + - rootViewController: ViewController to switch. |
| 169 | + - direction: Direction animation. Equal CATransitionSubType in CATransition. |
| 170 | + - duration: Duration animation. Default = 0.3. |
| 171 | + - backgroundColor: Background color when animation in process. Default is black. |
| 172 | + - backgroundImage: Image for background when animation in process. |
| 173 | + */ |
| 174 | + @objc public func switchRootViewControllerPushTransition(to rootViewController: UIViewController, |
| 175 | + direction: TransitionDirection, |
| 176 | + duration: CGFloat = 0.3, |
| 177 | + backgroundColor: UIColor? = nil, |
| 178 | + backgroundImage: UIImage) |
| 179 | + |
| 180 | + /** |
| 181 | + Manually animation: move snapshots views (old and new). |
| 182 | +
|
| 183 | + - Parameters: |
| 184 | + - rootViewController: ViewController to switch. |
| 185 | + - direction: Direction animation. Equal CATransitionSubType in CATransition. |
| 186 | + - inAnimation: Animation position for new ViewController. |
| 187 | + - outAnimation: Animation position for old ViewController. |
| 188 | + - duration: Duration animation. Default = 0.4. |
| 189 | + - options: UIViewAnimationOptions for UIView animations. |
| 190 | + */ |
| 191 | + @objc public func switchRootViewControllerManuallyMove(to rootViewController: UIViewController, |
| 192 | + direction: TransitionDirection, |
| 193 | + inAnimation: Bool = true, |
| 194 | + outAnimation: Bool = true, |
| 195 | + duration: CGFloat = 0.4, |
| 196 | + options: UIViewAnimationOptions = []) |
| 197 | + |
| 198 | +} |
| 199 | +``` |
| 200 | + |
| 201 | +#### Interface in Objective-C only (also only support in `AnimationSwitchRootViewControllerObjC`): |
| 202 | +```objc |
| 203 | + |
| 204 | +@interface UIApplication (PVRootWindow) |
| 205 | + + (nullable UIWindow*) sharedWindow; |
| 206 | +@end |
| 207 | + |
| 208 | + |
| 209 | +@interface UIWindow (PVAnimationSwitchRootViewController) |
| 210 | + |
| 211 | + //Core Animation: transition and temp background window |
| 212 | + - (void) setRootViewController:(UIViewController *)rootViewController |
| 213 | + withTransition:(CATransition*)transition |
| 214 | + backgroundColor:(nullable UIColor*)color |
| 215 | + andBackgroundView:(nullable UIView*)view; |
| 216 | + |
| 217 | + |
| 218 | + //Manually animation: move snapshots |
| 219 | + - (void) setRootViewController:(UIViewController *)rootViewController |
| 220 | + withManuallyInAnimation:(BOOL)inAnimation |
| 221 | + outAnimation:(BOOL)outAnimation |
| 222 | + routeType:(NSString*)transitionSubType |
| 223 | + duration:(CGFloat)duration |
| 224 | + options:(UIViewAnimationOptions)options; |
| 225 | + |
| 226 | + |
| 227 | + //Simplify function |
| 228 | + - (void) setRootViewController:(UIViewController *)rootViewController |
| 229 | + pushTransactionRoute:(NSString*)transitionSubType |
| 230 | + duration:(CGFloat)duration |
| 231 | + backgroundColor:(nullable UIColor*)color |
| 232 | + andBackgroundView:(nullable UIView*)view; |
| 233 | + |
| 234 | + - (void) setRootViewController:(UIViewController *)rootViewController |
| 235 | + pushTransactionRoute:(NSString*)transitionSubType |
| 236 | + duration:(CGFloat)duration |
| 237 | + backgroundColor:(nullable UIColor*)color |
| 238 | + andBackgroundImage:(nullable UIImage*)image; |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + - (void) setRootViewController:(UIViewController *)rootViewController |
| 243 | + pushManuallyRoute:(NSString*)transitionSubType |
| 244 | + duration:(CGFloat)duration; |
| 245 | + |
| 246 | +@end |
| 247 | + |
| 248 | +``` |
| 249 | + |
| 250 | + |
| 251 | +#### Example use in swift: |
| 252 | +```swift |
| 253 | + |
| 254 | +UIApplication.sharedWindow()?.switchRootViewControllerPushTransition(to: newViewController, |
| 255 | + direction: .fromRight, |
| 256 | + backgroundColor: UIColor.white) |
| 257 | + |
| 258 | +UIApplication.sharedWindow()?.switchRootViewControllerManuallyMove(to: newViewController, |
| 259 | + direction: .fromLeft) |
| 260 | + |
| 261 | +``` |
| 262 | + |
| 263 | +More examples you can find in the project in this repository. |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | +## Author |
| 268 | + |
| 269 | +[**ViR (Короткий Виталий)**](http://provir.ru) |
| 270 | + |
| 271 | + |
| 272 | +## License |
| 273 | + |
| 274 | +AnimationSwitchRootViewController is released under the MIT license. [See LICENSE](https://github.com/ProVir/AnimationSwitchRootViewController/blob/master/LICENSE) for details. |
9 | 275 |
|
10 | 276 |
|
0 commit comments