Skip to content

Instagram like UIViewController transition for iOS

License

Notifications You must be signed in to change notification settings

brenoxp/BXTransition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BXTransition

CI Status Version License Platform

Example

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

Gif

Usage - Present

import BXTransition

class ViewController: UIViewController {
  
  var transition: BXTransition!
  let interactor = Interactor()

  override func viewDidLoad() {
    
  }
  
  override func viewDidAppear(_ animated: Bool) {
    transition = BXTransition(viewController: self)
    transition.interactor = interactor
    
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    
    let viewController1 = storyboard.instantiateViewController(withIdentifier: "ViewController1")
    viewController1.transitioningDelegate = self
    transition.set(viewController: viewController1, forDirection: .right)
  }
  
  @IBAction func pangGesture(_ sender: Any) {
    guard let gesture = sender as? UIGestureRecognizer else { return }
    transition.panGesture(view: view, gesture: gesture)
  }
}

extension ViewController: UIViewControllerTransitioningDelegate {
  func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return transition
  }
  
  func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
    return interactor.hasStarted ? interactor : nil
  }
}

Usage - Dismiss

import BXTransition

class ViewController1: UIViewController {
  var transition: BXTransition!
  let interactor = Interactor()
 
  override func viewDidAppear(_ animated: Bool) {
    transitioningDelegate = self

    transition = BXTransition(viewController: self)
    transition.interactor = interactor
    transition.setDismiss(directionAccepted: .left)
  }
  
  @IBAction func pangGesture(_ sender: Any) {
    guard let gesture = sender as? UIGestureRecognizer else { return }
    transition.panGesture(view: view, gesture: gesture)
  }
}

extension ViewController1: UIViewControllerTransitioningDelegate {
  func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return transition
  }
  
  func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
    return interactor.hasStarted ? interactor : nil
  }
}

Installation

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

pod 'BXTransition'

Author

Breno Xavier - [email protected]

License

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

About

Instagram like UIViewController transition for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published