Swiftpack.co - ProVir/AnimationSwitchRootViewController as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ProVir.
ProVir/AnimationSwitchRootViewController 1.0.3
Extension for UIWindow - animation switch rootViewController in UIWindow.
⭐️ 4
🕓 2 years ago
iOS
.package(url: "https://github.com/ProVir/AnimationSwitchRootViewController.git", from: "1.0.3")

AnimationSwitchRootViewController

CocoaPods Compatible Carthage Compatible Platform License

Extension for UIWindow - animation switch rootViewController in UIWindow. Support Objective-C, Swift 5. If you need pure Objective-C, use AnimationSwitchRootViewController/ObjC.

Example demo gif

Features

  • ☑ 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).

Requirements

  • iOS 8.0+
  • Xcode 10.2
  • Swift 5.0

Communication

  • 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.

Installation

CocoaPods

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

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.

Manually

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.


Usage

Interface in Swift (also Objective-C support):

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 in Objective-C only (also only support in AnimationSwitchRootViewControllerObjC):


@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

Example use in swift:


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.

Author

ViR (Короткий Виталий)

License

AnimationSwitchRootViewController is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 4
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

SPM and Swift 5.3
2 years ago

Support SPM and up swift versions to 5.3

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics