{"id":2377,"url":"https://github.com/lkzhao/ElasticTransition","last_synced_at":"2025-08-02T23:33:20.003Z","repository":{"id":47491640,"uuid":"48133320","full_name":"lkzhao/ElasticTransition","owner":"lkzhao","description":"A UIKit custom transition that simulates an elastic drag. Written in Swift.","archived":false,"fork":false,"pushed_at":"2020-05-10T18:37:32.000Z","size":7299,"stargazers_count":2175,"open_issues_count":21,"forks_count":176,"subscribers_count":43,"default_branch":"master","last_synced_at":"2024-04-24T14:48:06.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lkzhao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-16T20:25:27.000Z","updated_at":"2024-04-18T20:38:56.000Z","dependencies_parsed_at":"2022-07-22T02:02:20.289Z","dependency_job_id":null,"html_url":"https://github.com/lkzhao/ElasticTransition","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lkzhao%2FElasticTransition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lkzhao%2FElasticTransition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lkzhao%2FElasticTransition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lkzhao%2FElasticTransition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lkzhao","download_url":"https://codeload.github.com/lkzhao/ElasticTransition/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228503196,"owners_count":17930534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:12.291Z","updated_at":"2024-12-06T17:31:02.801Z","avatar_url":"https://github.com/lkzhao.png","language":"Swift","funding_links":[],"categories":["UI","HarmonyOS","Libs","Content","User Interface"],"sub_categories":["Transition","Windows Manager","Layout","Other free courses","UI","Mobile"],"readme":"# ElasticTransition (Swift 3)\n\n[![Version](https://img.shields.io/cocoapods/v/ElasticTransition.svg?style=flat)](http://cocoapods.org/pods/ElasticTransition)\n[![License](https://img.shields.io/cocoapods/l/ElasticTransition.svg?style=flat)](http://cocoapods.org/pods/ElasticTransition)\n[![Platform](https://img.shields.io/cocoapods/p/ElasticTransition.svg?style=flat)](http://cocoapods.org/pods/ElasticTransition)\n\nA UIKit custom modal transition that simulates an elastic drag. Written in Swift.\n\n![demo](https://github.com/lkzhao/ElasticTransition/blob/master/imgs/demo.gif?raw=true)\n\n###Thanks to Matt Garnett (@c-o-l-o-r) for converting ElasticTransition to Swift 3\n\n###Also, special thanks to [@taglia3](https://github.com/taglia3) for developing the [Objective-C version] (https://github.com/taglia3/ElasticTransition-ObjC). Check it out!\n\n## Requirements\n\n* Xcode 8 or higher\n* iOS 8.0 or higher\n* Swift 3.0\n\n## Installation\n\n####CocoaPods\n\n```ruby\nuse_frameworks!\npod \"ElasticTransition\"\n```\n\n## Usage\n\n### Simple\n\n```swift\nimport ElasticTransition\n// make your view controller a subclass of ElasticModalViewController\n// present it as normal\nclass YourModalViewController:ElasticModalViewController{ \n  // ... \n}\n\nclass RootViewController:UIViewController{\n  // ...\n  @IBAction func modalBtnTouched(sender: AnyObject) {\n    performSegueWithIdentifier(\"modalSegueIdentifier\", sender: self)\n\n    // or if you want to do customization ---------------------\n    let modalViewController = UIStoryboard(name: \"Main\", bundle: nil).instantiateViewControllerWithIdentifier(\"modalViewControllerIdentifier\") as! YourModalViewController\n    // customization:\n    modalViewController.modalTransition.edge = .Left\n    modalViewController.modalTransition.radiusFactor = 0.3\n    // ...\n\n    presentViewController(modalViewController, animated: true, completion: nil)\n  }\n}\n```\n\n### Attributes you can set:\n```swift\n  // screen edge of the transition\n  public var edge:Edge\n  // animation stiffness - determines the speed of the animation\n  public var stiffness:CGFloat = 0.2\n  // animation damping - determines the bounciness of the animation \n  public var damping:CGFloat = 0.2\n  // Background view transform\n  public var transformType:ElasticTransitionBackgroundTransform = .TranslateMid\n  // The curvature of the elastic edge.\n  public var radiusFactor:CGFloat = 0.5\n  /**\n   Determines whether or not the view edge will stick to\n   the initial position when dragged.\n   **Only effective when doing a interactive transition**\n   */\n  public var sticky:Bool = true\n  /**\n   The initial position of the simulated drag when static animation is performed\n   i.e. The static animation will behave like user is dragging from this point\n   **Only effective when doing a static transition**\n   */\n  public var startingPoint:CGPoint?\n  /**\n   The background color of the container when doing the transition\n   */\n  public var containerColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 1.0)\n  /**\n   The color of the overlay when doing the transition\n   */\n  public var overlayColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 0.5)\n  /**\n   Whether or not to display the shadow. Will decrease performance.\n   */\n  public var showShadow:Bool = false\n  /**\n   The shadow color of the container when doing the transition\n   */\n  public var shadowColor:UIColor = UIColor(red: 100/255, green: 122/255, blue: 144/255, alpha: 1.0)\n  /**\n   The shadow radius of the container when doing the transition\n   */\n  public var shadowRadius:CGFloat = 50\n```\n\n\n------------------------\n## Advance Usage\n\nThis work with any view controller. \n\nIn prepareForSegue, assign the transition to be the transitioningDelegate of the destinationViewController.\nAlso, dont forget to set the modalPresentationStyle to .Custom\n\n```swift\nvar transition = ElasticTransition()\noverride func viewDidLoad() {\n  super.viewDidLoad()\n\n  // customization\n  transition.edge = .Left \n  transition.sticky = false\n  // etc\n}\noverride func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {\n  segue.destinationViewController.transitioningDelegate = transition\n  segue.destinationViewController.modalPresentationStyle = .Custom\n}\n```\n\n(Optional) In your modal view controller implement the ElasticMenuTransitionDelegate and provide the contentLength\n```swift\nclass MenuViewController: UIViewController, ElasticMenuTransitionDelegate {\n  var contentLength:CGFloat = 320\n  // ...\n}\n```\n\n##### Interactive transition for modal transition\n\nFirst, construct a pan gesture recognizer\n\n```swift\nlet panGR = UIPanGestureRecognizer(target: self, action: \"handlePan:\")\nview.addGestureRecognizer(panGR)\n```\n\nThen implement your gesture handler and fo the following:\n\n```swift\nfunc handlePan(pan:UIPanGestureRecognizer){\n  if pan.state == .Began{\n    // Here, you can do one of two things\n    // 1. show a viewcontroller directly\n    let nextViewController = // construct your VC ...\n    transition.startInteractiveTransition(self, toViewController: nextViewController, gestureRecognizer: pan)\n    // 2. perform a segue\n    transition.startInteractiveTransition(self, segueIdentifier: \"menu\", gestureRecognizer: pan)\n  }else{\n    transition.updateInteractiveTransition(gestureRecognizer: pan)\n  }\n}\n```\n\n##### Interactive transition for dismissing the modal\n\n1. Implement ElasticMenuTransitionDelegate in your modal view controller and set\n\n```swift\n  var dismissByBackgroundTouch = true\n  var dismissByBackgroundDrag = true\n  var dismissByForegroundDrag = true\n```\n\n2. Or use your own panGestureRecognizer and call dissmissInteractiveTransition in your handler\n```swift\nfunc handlePan(pan:UIPanGestureRecognizer){\n  if pan.state == .Began{\n    transition.dissmissInteractiveTransition(self, gestureRecognizer: pan, completion: nil)\n  }else{\n    transition.updateInteractiveTransition(gestureRecognizer: pan)\n  }\n}\n```\n\n## Author\n\nLuke Zhao, me@lkzhao.com\n\n## License\n\nElasticTransition is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flkzhao%2FElasticTransition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flkzhao%2FElasticTransition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flkzhao%2FElasticTransition/lists"}