SolarTransition 0.1.1

SolarTransition 0.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by Matija Kruljac.




  • By
  • Matija Kruljac

SolarTransition is a cocoapod for circular animated transition from UIButton which is a square shape with rounded corners by half of its width or height.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • Xcode 8
  • Swift 3.0

Installation

SolarTransition is available through CocoaPods. To install it, simply add the following lines to your Podfile:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod "SolarTransition"
end

Usage

Code below is used when transition starts from first ViewController (fromViewController) to second ViewController (toViewController) with a tap on rounded UIButton. SolarTransitionAnimator has to be initialized with duration of animation, transition type and with originView. After creating toViewController, originView of toViewController is rounded UIButton which is mentioned earlier and needs to be set. Last thing that is left is just to call present() method of SolarTransitionAnimator with toViewController and navigationController.

let solarTransitionAnimator = SolarTransitionAnimator(
    withDuration: TimeInterval(0.3),
    forTransitionType: .presenting,
    originView: startSolarTransitionButton
)
let toViewController = ToViewController(
    nibName: "ToViewController",
    navigationService: navigationService
)
toViewController.originView = startSolarTransitionButton
solarTransitionAnimator.present(
    viewController: toViewController,
    inNavigationController: navigationController
)

Before transition can be successful second ViewController (toViewController) needs to implement SolarTransitionOriginProtocol.

public protocol SolarTransitionOriginProtocol {
    var originView: UIView? { get set }
}

This protocol demands declaration of originView property which is set in first ViewController (fromViewController).

When dissmising second ViewController (toViewController) SolarTransitionAnimator must be initialized with duration of animation, transition type and with originView. For dissmising ViewController dismiss() method of SolarTransitionAnimator is called.

class ToViewController: UIViewController, SolarTransitionOriginProtocol {

    // ...
    guard let originView = originView else { return }
    let solarTransitionAnimator = SolarTransitionAnimator(
          withDuration: TimeInterval(0.5),
          forTransitionType: .dismissing,
          originView: originView
     )
     solarTransitionAnimator.dismiss(
          viewController: self,
          inNavigationController: navigationController
     )
}

Author

Matija Kruljac, [email protected]

License

SolarTransition is available under the MIT license. See the LICENSE file for more info.