Giter Club home page Giter Club logo

elastictransition's Introduction

ElasticTransition (Swift 3)

Version License Platform

A UIKit custom modal transition that simulates an elastic drag. Written in Swift.

demo

###Thanks to Matt Garnett (@c-o-l-o-r) for converting ElasticTransition to Swift 3

###Also, special thanks to @taglia3 for developing the [Objective-C version] (https://github.com/taglia3/ElasticTransition-ObjC). Check it out!

Requirements

  • Xcode 8 or higher
  • iOS 8.0 or higher
  • Swift 3.0

Installation

####CocoaPods

use_frameworks!
pod "ElasticTransition"

Usage

Simple

import ElasticTransition
// make your view controller a subclass of ElasticModalViewController
// present it as normal
class YourModalViewController:ElasticModalViewController{ 
  // ... 
}

class RootViewController:UIViewController{
  // ...
  @IBAction func modalBtnTouched(sender: AnyObject) {
    performSegueWithIdentifier("modalSegueIdentifier", sender: self)

    // or if you want to do customization ---------------------
    let modalViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("modalViewControllerIdentifier") as! YourModalViewController
    // customization:
    modalViewController.modalTransition.edge = .Left
    modalViewController.modalTransition.radiusFactor = 0.3
    // ...

    presentViewController(modalViewController, animated: true, completion: nil)
  }
}

Attributes you can set:

  // screen edge of the transition
  public var edge:Edge
  // animation stiffness - determines the speed of the animation
  public var stiffness:CGFloat = 0.2
  // animation damping - determines the bounciness of the animation 
  public var damping:CGFloat = 0.2
  // Background view transform
  public var transformType:ElasticTransitionBackgroundTransform = .TranslateMid
  // The curvature of the elastic edge.
  public var radiusFactor:CGFloat = 0.5
  /**
   Determines whether or not the view edge will stick to
   the initial position when dragged.
   **Only effective when doing a interactive transition**
   */
  public var sticky:Bool = true
  /**
   The initial position of the simulated drag when static animation is performed
   i.e. The static animation will behave like user is dragging from this point
   **Only effective when doing a static transition**
   */
  public var startingPoint:CGPoint?
  /**
   The background color of the container when doing the transition
   */
  public var containerColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 1.0)
  /**
   The color of the overlay when doing the transition
   */
  public var overlayColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 0.5)
  /**
   Whether or not to display the shadow. Will decrease performance.
   */
  public var showShadow:Bool = false
  /**
   The shadow color of the container when doing the transition
   */
  public var shadowColor:UIColor = UIColor(red: 100/255, green: 122/255, blue: 144/255, alpha: 1.0)
  /**
   The shadow radius of the container when doing the transition
   */
  public var shadowRadius:CGFloat = 50

Advance Usage

This work with any view controller.

In prepareForSegue, assign the transition to be the transitioningDelegate of the destinationViewController. Also, dont forget to set the modalPresentationStyle to .Custom

var transition = ElasticTransition()
override func viewDidLoad() {
  super.viewDidLoad()

  // customization
  transition.edge = .Left 
  transition.sticky = false
  // etc
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  segue.destinationViewController.transitioningDelegate = transition
  segue.destinationViewController.modalPresentationStyle = .Custom
}

(Optional) In your modal view controller implement the ElasticMenuTransitionDelegate and provide the contentLength

class MenuViewController: UIViewController, ElasticMenuTransitionDelegate {
  var contentLength:CGFloat = 320
  // ...
}
Interactive transition for modal transition

First, construct a pan gesture recognizer

let panGR = UIPanGestureRecognizer(target: self, action: "handlePan:")
view.addGestureRecognizer(panGR)

Then implement your gesture handler and fo the following:

func handlePan(pan:UIPanGestureRecognizer){
  if pan.state == .Began{
    // Here, you can do one of two things
    // 1. show a viewcontroller directly
    let nextViewController = // construct your VC ...
    transition.startInteractiveTransition(self, toViewController: nextViewController, gestureRecognizer: pan)
    // 2. perform a segue
    transition.startInteractiveTransition(self, segueIdentifier: "menu", gestureRecognizer: pan)
  }else{
    transition.updateInteractiveTransition(gestureRecognizer: pan)
  }
}
Interactive transition for dismissing the modal
  1. Implement ElasticMenuTransitionDelegate in your modal view controller and set
  var dismissByBackgroundTouch = true
  var dismissByBackgroundDrag = true
  var dismissByForegroundDrag = true
  1. Or use your own panGestureRecognizer and call dissmissInteractiveTransition in your handler
func handlePan(pan:UIPanGestureRecognizer){
  if pan.state == .Began{
    transition.dissmissInteractiveTransition(self, gestureRecognizer: pan, completion: nil)
  }else{
    transition.updateInteractiveTransition(gestureRecognizer: pan)
  }
}

Author

Luke Zhao, [email protected]

License

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

elastictransition's People

Contributors

joelmbell avatar lkzhao avatar sairamkotha avatar wuxiao356 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  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

elastictransition's Issues

viewWillAppear on disappearing ViewController is being called accidentally with UIViewController

Hello,

When using UIViewController by setting the delegate to ElasticTransition, I noticed that viewWillAppear of the old ViewController is being called again right after viewWillDisappear of that same ViewController.

For example, ViewController-A pushes to ViewController-B, the viewWillDisappear will be called on A, then viewWillAppear will be called on A (this should not be called). This may leads to many unexpected problems for some projects that have some logic bound to viewWillAppear.

Fixed controls while transitioning, how to?

Firstly, great work on this transition library

Has anyone made this work inside a tab bar controller,

or how do I make such that some UI elements to always stay fixed on screen before and after transitioning?

none animated dismissViewController bug

Sorry lkzhao that I don't really have time to debug and make a pull request to help you but I hope I could at least report what I found while using your control.

Currently dismiss a ViewController which was presented modally with custom transition as ElasticTransition only work with animated = true. If animated is false, it will result in black / empty screen.

I guess this has something with rendering the underneath view controller while performing the custom transition.

Strange bug when swiping quickly

I have a project where I have a UINavigationController and it's root controller. I have setup a modal segue from the nav controller to another controller in my Storyboard. I have attached the pan gesture to the nav controller's UINavigationBar. When the user swipes down on the nav bar, it triggers the modal segue that I setup on the storyboard, and the user can fully control the transition. This all works perfectly.

However, If I swipe very fast, about 1 out of 10 times something very strange happens. Here's a screenshot:
screen shot 2016-03-07 at 1 44 59 pm

The main white view is where everything should be, but as you can see all of the other views are located up at the top and are not visible on screen at all. The top views have a y value of -667, which is the height in points of the iPhone 6 I am testing on.

I need to fix this. For some reason when the user does a fast swipe all of this happens and then they basically get stuck with a blank screen.

Swift 2.3 isn't letting me do performSegueWithIdentifier with this pod

I used to be able to call performSegueWithIdentifier using the iOS 9 SDK and Swift 2.2. However, it isn't working anymore in Swift 2.3 with the iOS 10 SDK. When I call peformSegueWithIdentifier there is a fatal error because the presentingViewController is nil and we are force unwrapping it.

Here is a screenshot:
screen shot 2016-06-17 at 11 31 26 am

Looking at the documentation it says that:

This parameter may also be nil to indicate that the presenting view controller will be determined later.

I'm currently trying to debug this but I am having some difficulty on finding a fix.
Thanks for this amazing library by the way!

Storyboard unwind is not supported

Hello,

On UINavigationController with delegate set to ElasticTransition, the Unwind completely breaks. Can you fix this somehow? Thank you.

wrong width when presenting a ViewController on top of ViewController presented by ElasticTransition

Sorry lkzhao that I don't really have time to debug and make a pull request to help you but I hope I could at least report what I found while using your control.

Currently, I have a MenuViewController presented modally using ElasticTransition. When I present SettingViewController on top of MenuViewController, and then dismiss SettingViewController.... the MenuViewController underneath is full screen width instead of custom width set on contentLength variable.

I am using storyboard with autolayout, btw.

Thank you for the cool library.

Import issue

Hi,

I am using Xcode 7.3.1 and Swift 2.2
I am also using cocoa pods .

I installed the ElasticTransition project via cocoapods by adding the following lines
pod 'ElasticTransition', '~> 3.0.0'

the pod install went fine and the I see the frameworks downloaded in my project workspace which I added to my Project's linked frameworks section.

However I dont see that appearing when I try to import the lib.

Import ElasticTransition ( says "Cannot find underlying module for ElasticTransition" )
can you please check what the issue could be,

Thanks,
Priyadarshan

ElasticModalViewController "not open" error

When trying to subclass ElasticModalViewController in my project I get the error:

"Cannot inherit from non-open class 'ElasticModalViewController' outside of its defining module.

This happens because I've pulled in ElasticTransition with cocoa pods and its in a different module.

Merge 2.1.1 on to Master

There are a couple of bugs in the version 2.0.1 (like viewControllerForKey(UITransitionContextFromViewControllerKey) exc_bad_instruction). They are fixed on 2.1.1.
Please merge on to master.

Possible retain cycle found in the example project and my own code

Hi there! I have been using this library for a while now, great work, really appreciate it! I was debugging my own project (which installed elastic transition) for some memory issues. I think I ended up discovering some strange behavior in elastic transition. The deinit function was never called in my view controller, so I commented out all code trying to figure out where the retain cycle was. Finally I found out the transition function was the one that actually caused this in the parent view controller. I then ran the example project using instruments. Here is what I found:

screen shot 2016-06-24 at 7 44 37 pm

I also added deinit function to print something in the options view controller, but it was never printed until the second time the view controller is presented. I'm fairly sure there is a retain cycle somewhere. I then checked ElasticMenuTransitionDelegate trying to see if anything would have a strong reference to the view controller, but no luck there. Please take a look and let me know what you think. Thanks!

Does EdgePanTransition work for UITableView?

When try function handleLeftPan(pan:UIPanGestureRecognizer) in a UIView it works perfectly. But when try it on a UITableView, i got error "fatal error: unexpectedly found nil while unwrapping an Optional value" for code line transition.dissmissInteractiveTransition.

Already tried changing UIViewController to UITableViewController as below for function dissmissInteractiveTransition, but it's not working.
public func dissmissInteractiveTransition(viewController:UITableViewController, gestureRecognizer

Thank you and apologize in case it's a silly question.

transition becomes super slow in the new version

I've been using ElasticTransition for a while. I love it! But I just did a pod update, and the new updated code made my transition super slow. I thought it was something wrong with my own code, but it is super slow too when I ran the new code from the repo. Any idea what's going on?

strange behaviour when presenting navigation controller after presenting the options view controller

1.In the demo, after the actions took as described, the default transition disappear.
2.If I want the navigation view controller to be presented with the elastic transition, it seems that i should use nav.transitionDelegate = transition rather than nav.delegate = transition, but after doing that, something unexpected happened, my UIAlertViewController presented by my app disappear when it is presented, but it can still be interacted, like its view's alpha become 0 to me.

Swift 4 update?

Any plan for swift 4 update. There are two errors in MotionAnimation framework.

ElasticModalViewController not found

Hi, I imported ElasticTransition but when trying to make the UIViewController a ElasticModalViewController, it says "use of undeclared type".

How can I overcome this?

Can't seam to make it work correctly with navigation controller

Hi,
I have a project in which I use navigation controller and transition like "option" transition in your ezample project is not animating correctly. For example when I start the example project and tap on option button, the new controller slides from the bottom, and the parent controller slides upwards and dimes a bit so that the content of the parent controller is still visible. like in the picture:
simulator screen shot 16 feb 2016 12 05 34

As picture shows we can see the content of parent view controller it says: "navigation controller" in dimmed red letters and this is perfect, this is what I want. But when I add the navigation controller to the project and I add the following line as instructed in the manual:

self.navigationController?.delegate = transition

, no mater in which project the example one or in my project, this behaviour changes. It changes in a way that the content of a parent controller hides after cca. 1/2 of a second, and it reveals again when I try to scroll out the new controller:

simulator screen shot 16 feb 2016 12 12 56

Can you please help me to achieve the same result with project that use navigation controller?
Thx in advance...

PS. for second screenshot I had to change the segue to "present modally", cause with "show segue" the parent controller was all white.

Swift 3

it'd be cool to have a swift 3 version, if you have any interest to create a branch i would like to help with that.

UINavigationController bug

I'm using a UINavigationController and triggering a modal segue to another view controller. The transition uses the top edge.

There is a bug that happens sometimes where when I go to perform the segue, the navigation controller's view will flicker and jump up behind the view that we are about to present.

I can't say for sure, but I have a feeling that this could be avoided by not altering the navigation controller's view at all, and instead using a snapshot view. I created an interactive transition from scratch earlier today and have been able to avoid this issue completely by creating a snapshot view with UIApplication.sharedApplication().delegate?.window!!.snapshotViewAfterScreenUpdates(false)

I take a snapshot of the window to capture the nav bar, set the actual nav controller view to hidden, animate the snapshot view during the transition, and when the transition animation is done I unhide the real navigation controller view.

Unfortunately I don't have time to fully test this and submit a PR right now but hopefully this might help anyone else who comes across this problem.

Obj-C version

It would be interesting to develop an Objective-C version of this awesome transition.

Dragging View issue

Sometimes when dragging a view (presenting and dismissing), the app "freezes" and we can't navigate to other views.

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.