Giter VIP home page Giter VIP logo

view2viewtransition's Introduction

View2ViewTransition

Carthage compatible Pod Version Swift Version License MIT Plaforms

Simple framework for custom interactive viewController transition from one view to another view.

Installation

Carthage

github "naru-jpn/View2ViewTransition"

CocoaPods

pod 'View2ViewTransition'

Usage

Create TransitionController and implement presentation

// Create TransitionController
var transitionController: TransitionController = TransitionController()
// Present view controller with transition delegate
let presentedViewController: PresentedViewController = PresentedViewController()
presentedViewController.transitioningDelegate = transitionController

transitionController.present(viewController: presentedViewController, on: self, attached: presentedViewController, completion: nil)

(also supports push)

// Set transitionController as a navigation controller delegate and push.
let presentedViewController: PresentedViewController = PresentedViewController()

if let navigationController = self.navigationController {
   navigationController.delegate = transitionController
   transitionController.push(viewController: presentedViewController, on: self, attached: presentedViewController)
}

Presenting viewController conforms View2ViewTransitionPresenting

func initialFrame(userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect
func initialView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView
func prepereInitialView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> Void // (optional)

Presented viewController conforms View2ViewTransitionPresented

func destinationFrame(userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect
func destinationView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView
func prepareDestinationView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> Void // (optional)

Use UserInfo

You can set userInfo to notify indexPath or share resource etc.

transitionController.userInfo = ["key": "value", ...]

Modify Animation Parameters

Animate with custom animation parameters.

// For present
transitionController.presentAnimationController.usingSpringWithDamping = 0.7
transitionController.presentAnimationController.initialSpringVelocity = 0.0
transitionController.presentAnimationController.animationOptions = [.CurveEaseInOut]

// For dismiss
transitionController.dismissAnimationController.usingSpringWithDamping = 0.7
transitionController.dismissAnimationController.initialSpringVelocity = 0.0
transitionController.dismissAnimationController.animationOptions = [.CurveEaseInOut]

Debug Mode

If you have hierarchical view controllers (navigation controllers) in app, viewController to conform protocol is not intuitive. View2ViewTransition prints some information in debug mode.

let transitionController = TransitionController()
// ...
transitionController.debuging = true

Example

View2ViewTransitionExample

view2viewtransition's People

Contributors

1amageek avatar a2 avatar fromkk avatar kronik avatar naru-jpn avatar sgr-ksmt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

view2viewtransition's Issues

`transitionController.userInfo`'s type

If it's possible, would you change transitionController.userInfo's type to [String: Any] or [AnyHashable: Any]? πŸ™‡

// before
public final class TransitionController: NSObject {
    public var userInfo: [String: AnyObject]? = nil
}

// after
public final class TransitionController: NSObject {
    public var userInfo: [String: Any]? = nil // or [AnyHashable: Any]
}

I think its type should be [String: Any] or [AnyHashable: Any] in Swift3. πŸ€”

[Update] Swift 3

I want to adapt to Swift 3 this project.
Please create branch swift-3 .

Get black screen when cancel interactive transition

cancelInteractiveTransition()

let duration: Double = Double(self.duration)*Double(progress)
UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: .CurveEaseInOut, animations: {

    self.animationController.destinationTransitionView.frame = self.animationController.destinationFrame
    self.animationController.initialTransitionView.frame = self.animationController.destinationFrame

}, completion: { _ in

    // Cancel Transition
    self.animationController.destinationTransitionView.removeFromSuperview()
    self.animationController.initialTransitionView.removeFromSuperview()

    self.animationController.destinationView.hidden = false
    self.animationController.initialView.hidden = false
    self.transitionController.presentingViewController.view.removeFromSuperview()

    self.transitionContext.completeTransition(false)
})

The line self.transitionController.presentingViewController.view.removeFromSuperview() in DismissInteractiveTransition.swift makes that the app turns black if you use the root view controller as presentingViewController and the users cancel dismiss and dismiss later.

Comment that line works in my case and I don't know if it affects in other #cases

I made a pull request with my solution #21

Value of type 'TransitionController' has no member 'present'

Hi,

I just installed this library using CocoaPods and I have this error, but I use the exactly same code provided by demo project

        transitionController.userInfo = ["destinationIndexPath": indexPath, "initialIndexPath": indexPath]
        transitionController.present(viewController: presentedViewController, on: self, attached: presentedViewController, completion: nil)

Any idea ??

Thanks.

IGListKit

@naru-jpn can this be used with IGListKit?
Would appreciate a demo re-created using IGListKit
Specifically, getting the initialFrame and initialView from an IGListKit section is tricky.

Damping parameter

Could you also move animation damping into Animation Controllers property?

UIView snapshot increase the memory on iOS 10

The layer render of snapshotImage function increase the memory.

if let context: CGContext = UIGraphicsGetCurrentContext() {
	self.layer.render(in: context)
}

When I changed to

self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)

It solved my problem.

Method "present" is not available in Objective-C

Hi!

found that method:

public func present(viewController presentedViewController: UIViewController, on presentingViewController: UIViewController, attached: UIViewController, completion: (() -> Void)?) ...

is marked as unavailable.

How can we use this component in Objective-C?

Does not work with UINavigationController-based transitions

I noticed that you've only implemented the transition for modal view controller presentation. It would be awesome if you could support the UINavigationControllerDelegate-based transitions. For example, instead of a new view controller being presented modally, it's pushed onto the navigation controller stack. There are two methods to support this:

  • -navigationController:animationControllerForOperation:fromViewController:toViewController:
  • -navigationController:interactionControllerForAnimationController:

[Update]Swift 2.3

I want to adapt to Swift 2.3 this project.
Please create branch swift-2.3 .

TransitionControlelr causes memory-leak?

Perhaps, TransitionController causes memory leak 😨

class ViewControlelr {
    let transitionController = TransitionController() // strong ref
}
class TransitionController {
   fileprivate(set) var presentingViewController: UIViewController? // strong ref
}

To avoid causing memory leak, TransitionController.presentingViewController should be weak var ! πŸ™‡

'present(viewController:on:attached:completion:)' is unavailable

Hello! Thanks for this framework.

Please help me, I faced with this error 'present(viewController:on:attached:completion:)' is unavailable

So I'm trying to execute code

let transitionController = TransitionController()
        let imagePickerController = UIImagePickerController()
        imagePickerController.sourceType = .photoLibrary
        imagePickerController.modalPresentationStyle = .overFullScreen
        imagePickerController.transitioningDelegate = transitionController
        
        transitionController.present(viewController: imagePickerController, on: self, attached: imagePickerController, completion: nil)

How can I fix it? Thanks

Black screen when move to back

Hello I made test example with CollectionView and UIViewController, but when I tried to back I see a black screen around presented controller. How can I fix it?

PresentedController code

class ChatPhotoBrowser: UIViewController {

    weak var transitionController: TransitionController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.clipsToBounds = true
        edgesForExtendedLayout = []
    }


}

extension ChatPhotoBrowser: View2ViewTransitionPresented {
    
    func destinationFrame(_ userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect {
        return view.frame
    }
    
    func destinationView(_ userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView {
        return view
    }
    
    func prepareDestinationView(_ userInfo: [String: AnyObject]?, isPresenting: Bool) {
        
        if isPresenting {
            view.layoutIfNeeded()
        }
    }
}

Presenting controller code

extension ChatMessageViewController: View2ViewTransitionPresenting {
    
    func initialFrame(_ userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect {
        // test data
        return CGRect(x: 0, y: 100, width: 100, height: 100)
    }
    
    func initialView(_ userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView {
        return view
    }
    
    func prepareInitialView(_ userInfo: [String : AnyObject]?, isPresenting: Bool) {
        view.layoutIfNeeded()
    }
    
}

Add badges

Hi
Below the title please add badges for carthage compatibility, pod version, Swift version, license and platform like this:
Carthage compatible Pod Version Swift Version License MIT Plaforms

Using View2View transition between 2 objective-c views

Hi,

I was wondering if there is a way to use view2viewtransition between 2 objective c views? Basically I want to use this library 2 show transition effect between 2 xib using objective c code. Hope I ma being clear on my question.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.