Extension for UIWindow - animation switch rootViewController in UIWindow. Support Objective-C, Swift 5. If you need pure Objective-C, use AnimationSwitchRootViewController/ObjC.
- Change rootViewController in UIWindow with animation.
- Get main UIWindow from UIApplication static function sharedWindow().
- Support CATransaction with backgrounds color, UIVIew or UIImage.
- Support animation move snapshots (manually).
- iOS 8.0+
- Xcode 10.2
- Swift 5.0
- If you need help, go to provir.ru
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.6.0+ is required to build AnimationSwitchRootViewController 1.0.0+.
To integrate AnimationSwitchRootViewController into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target '<Your Target Name>' do
pod 'AnimationSwitchRootViewController', '~> 1.0'
end
Then, run the following command:
$ pod install
if you need pure Objective-C, use AnimationSwitchRootViewController/ObjC:
pod 'AnimationSwitchRootViewController/ObjC', '~> 1.0'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate AnimationSwitchRootViewController into your Xcode project using Carthage, specify it in your Cartfile
:
github "ProVir/AnimationSwitchRootViewController" ~> 1.0
Run carthage update
to build the framework and drag the built AnimationSwitchRootViewController.framework
into your Xcode project.
if you need pure Objective-C, use AnimationSwitchRootViewControllerObjC - drag the built AnimationSwitchRootViewControllerObjC.framework
into your Xcode project.
If you prefer not to use any of the aforementioned dependency managers, you can integrate AnimationSwitchRootViewController into your project manually.
Copy files from directory AnimationSwitchRootViewController
in your project.
if you need pure Objective-C, don't copy *.swift
files.
public extension UIApplication {
@objc public static func sharedWindow() -> UIWindow?
}
public extension UIWindow {
///Transition Direction - equal CATransitionSubType.
@objc public enum TransitionDirection : Int {
case fromRight
case fromLeft
case fromTop
case fromBottom
}
/**
Core Animation: custom transition and temp background window.
- Parameters:
- rootViewController: ViewController to switch.
- transition: Custom core animation transition.
- backgroundColor: Background color when animation in process. Default is black.
- backgroundView: View for background when animation in process.
*/
@objc public func switchRootViewController(to rootViewController: UIViewController,
withTransition transition: CATransition,
backgroundColor: UIColor? = nil,
backgroundView: UIView? = nil)
/**
Core Animation: push transition and temp background window.
- Parameters:
- rootViewController: ViewController to switch.
- direction: Direction animation. Equal CATransitionSubType in CATransition.
- duration: Duration animation. Default = 0.3.
- backgroundColor: Background color when animation in process. Default is black.
- backgroundView: View for background when animation in process.
*/
@objc public func switchRootViewControllerPushTransition(to rootViewController: UIViewController,
direction: TransitionDirection,
duration: CGFloat = 0.3,
backgroundColor: UIColor? = nil,
backgroundView: UIView? = nil)
/**
Core Animation: push transition and temp background window with image as background.
- Parameters:
- rootViewController: ViewController to switch.
- direction: Direction animation. Equal CATransitionSubType in CATransition.
- duration: Duration animation. Default = 0.3.
- backgroundColor: Background color when animation in process. Default is black.
- backgroundImage: Image for background when animation in process.
*/
@objc public func switchRootViewControllerPushTransition(to rootViewController: UIViewController,
direction: TransitionDirection,
duration: CGFloat = 0.3,
backgroundColor: UIColor? = nil,
backgroundImage: UIImage)
/**
Manually animation: move snapshots views (old and new).
- Parameters:
- rootViewController: ViewController to switch.
- direction: Direction animation. Equal CATransitionSubType in CATransition.
- inAnimation: Animation position for new ViewController.
- outAnimation: Animation position for old ViewController.
- duration: Duration animation. Default = 0.4.
- options: UIViewAnimationOptions for UIView animations.
*/
@objc public func switchRootViewControllerManuallyMove(to rootViewController: UIViewController,
direction: TransitionDirection,
inAnimation: Bool = true,
outAnimation: Bool = true,
duration: CGFloat = 0.4,
options: UIViewAnimationOptions = [])
}
@interface UIApplication (PVRootWindow)
+ (nullable UIWindow*) sharedWindow;
@end
@interface UIWindow (PVAnimationSwitchRootViewController)
//Core Animation: transition and temp background window
- (void) setRootViewController:(UIViewController *)rootViewController
withTransition:(CATransition*)transition
backgroundColor:(nullable UIColor*)color
andBackgroundView:(nullable UIView*)view;
//Manually animation: move snapshots
- (void) setRootViewController:(UIViewController *)rootViewController
withManuallyInAnimation:(BOOL)inAnimation
outAnimation:(BOOL)outAnimation
routeType:(NSString*)transitionSubType
duration:(CGFloat)duration
options:(UIViewAnimationOptions)options;
//Simplify function
- (void) setRootViewController:(UIViewController *)rootViewController
pushTransactionRoute:(NSString*)transitionSubType
duration:(CGFloat)duration
backgroundColor:(nullable UIColor*)color
andBackgroundView:(nullable UIView*)view;
- (void) setRootViewController:(UIViewController *)rootViewController
pushTransactionRoute:(NSString*)transitionSubType
duration:(CGFloat)duration
backgroundColor:(nullable UIColor*)color
andBackgroundImage:(nullable UIImage*)image;
- (void) setRootViewController:(UIViewController *)rootViewController
pushManuallyRoute:(NSString*)transitionSubType
duration:(CGFloat)duration;
@end
UIApplication.sharedWindow()?.switchRootViewControllerPushTransition(to: newViewController,
direction: .fromRight,
backgroundColor: UIColor.white)
UIApplication.sharedWindow()?.switchRootViewControllerManuallyMove(to: newViewController,
direction: .fromLeft)
More examples you can find in the project in this repository.
AnimationSwitchRootViewController is released under the MIT license. See LICENSE for details.