{"id":15038119,"url":"https://github.com/loopeer/alerttransition","last_synced_at":"2025-04-05T20:06:35.718Z","repository":{"id":37359565,"uuid":"88871326","full_name":"loopeer/AlertTransition","owner":"loopeer","description":"AlertTransition is a extensible library for making view controller transitions, especially for alert transitions.","archived":false,"fork":false,"pushed_at":"2017-12-28T07:55:16.000Z","size":23747,"stargazers_count":577,"open_issues_count":0,"forks_count":60,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-04-24T14:48:36.417Z","etag":null,"topics":["alert","alertview","alertviewcontroller","animation","sidemenu","swift4","transition"],"latest_commit_sha":null,"homepage":null,"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/loopeer.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":"2017-04-20T13:54:30.000Z","updated_at":"2024-03-30T12:09:30.000Z","dependencies_parsed_at":"2022-08-20T18:50:38.203Z","dependency_job_id":null,"html_url":"https://github.com/loopeer/AlertTransition","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAlertTransition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAlertTransition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAlertTransition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAlertTransition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopeer","download_url":"https://codeload.github.com/loopeer/AlertTransition/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393569,"owners_count":20931812,"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":["alert","alertview","alertviewcontroller","animation","sidemenu","swift4","transition"],"created_at":"2024-09-24T20:37:10.233Z","updated_at":"2025-04-05T20:06:35.691Z","avatar_url":"https://github.com/loopeer.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# AlertTransition\n\n![Xcode 8.2+](https://img.shields.io/badge/Xcode-8.2%2B-blue.svg)\n![iOS 8.0+](https://img.shields.io/badge/iOS-8.0%2B-blue.svg)\n![Swift 3.0+](https://img.shields.io/badge/Swift-3.0%2B-orange.svg)\n![Swift 4](https://img.shields.io/badge/Swift-4-orange.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-Compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Version](https://img.shields.io/cocoapods/v/AlertTransition.svg?style=flat)](https://cocoapods.org/pods/AlertTransition)\n\n**AlertTransition** is a extensible library for making view controller transitions, especially for alert transitions. \n\n## Overview\n\n**AlertTransition** is a super class, make basic structure, and no default animation realized.\n\n**EasyTransition** is a subclass of **AlertTransition**. with it, you can compose custom transition with translation, scale, rotation and alpha. You can also change background with custom color or UIBlurEffect. It support changing device orientation. And it is easy to use both in code or storyboard.\n\n\u003ctable\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n    \u003cimg src=\"Media/EasyTransition.gif\" width=\"300\"/\u003e\n  \u003c/td\u003e\n  \u003ctd\u003e\n    \u003cimg src=\"Media/BackgroundType.gif\" width=\"300\"/\u003e\n  \u003c/td\u003e\n  \u003ctd\u003e\n    \u003cimg src=\"Media/changeOrientation.gif\" width=\"400\"/\u003e\n  \u003c/td\u003e\n \u003c/tr\u003e\n\u003c/table\u003e\n\n**MenuTransition** is a subclass of **AlertTransition**. With it, you can make a side menu with a few line of codes.\n\n\u003cimg src=\"Media/MenuTransition.gif\" width=\"320\"/\u003e\n\n**TrolleyTransition** is a subclass of **AlertTransition**. With it, you can make a trolley with a few line of codes.\n\n\u003cimg src=\"Media/TrolleyTransition.gif\" width=\"320\"/\u003e\n\n***You can subclass AlertTransition, and write your custom transition***. And you can also wrap other transition effect with AlertTransition, such as [BubbleTransition](https://github.com/andreamazz/BubbleTransition) or [StarWars.iOS](https://github.com/Yalantis/StarWars.iOS). \n\n\u003ctable\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n    \u003cimg src=\"Media/BubbleTransition.gif\" width=\"300\"/\u003e\n  \u003c/td\u003e\n  \u003ctd\u003e\n    \u003cimg src=\"Media/StarWarsTransition.gif\" width=\"300\"/\u003e\n  \u003c/td\u003e\n \u003c/tr\u003e\n\u003c/table\u003e\n\n## AlertTransition\n\n### How To Use\n\nIt is pretty simple to use AlertTransition\n\n```swift\n// First, initialize your presented controller\nlet alert = SomeController()\n// Second, initialize a subclass of AlertTransition, such as EasyTransition, configure your controller with it\nalert.at.transition = EasyTransition()\n// Present your controller, Amazing!!\npresent(alert, animated: true, completion: nil)\n```\n\nIf you use storyboard\n\n```swift\noverride func prepare(for segue: UIStoryboardSegue, sender: Any?) {\n\n\t// First, find presented controller\n\tlet controller = segue.destination \n\t// Second, initialize a subclass of AlertTransition, such as EasyTransition, configure your controller with it  \n\tcontroller.at.transition = EasyTransition()\n}\n```\n\n```swift\n@IBAction func dismissButtonClicked() {\n    dismiss(animated: true, completion: nil)\n}\n```\n\n### Frame of Presented Controller\n\nHow to set the frame of presented controller? Conform to **AlertFrameProtocol** or **Self-sizing**\n\n#### AlertFrameProtocol\n\nConforms to AlertFrameProtocol, provide your desired frame through property **alertFrame**\n\n```swift\nclass SomeController: UIViewController, AlertFrameProtocol {\n    \n    var alertFrame: CGRect {\n        let x = (UIScreen.main.bounds.size.width - 200) / 2\n        let y = (UIScreen.main.bounds.size.height - 250) / 2\n        return CGRect(x: x, y: y, width: 200, height: 250)\n    }\n}\n```\n\n#### Self-sizing\n\nYou need an unbroken chain of constraints and views (with defined heights) to fill the area between the controller view’s top edge and its bottom edge, and you also need one (with defined widths) between the controller view’s left edge and its right edge. If you know how to write [Self-sizing Cell](https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html), this will be easy to you.\n\nAlertTransition will calculate view's width and height, and set the presented controller in center of screen.\n\nSometimes, there maybe constraint conflicts. Among the chain of constraints, pick one constraint and reduce it's priority (eg: from 1000 to 999), everything will be fine.\n\nYou can find demo code in SnapKitAlertController.swift and Main.storyboard.\n\n### Change background\n\nYou can change alert background with ***backgroundType***. Effect gif is the second image above. \n\n```swift\nlet alert = SomeController()\n\n// It is a property of AlertTransition, you can use any subclass, just use EasyTransition as an example\nlet transition = EasyTransition()\ntransition.backgroundType = .blurEffect(style: .extraLight, alpha: 0.9)\n// transition.backgroundType = .blurEffect(style: .light, alpha: 0.9)\n// transition.backgroundType = .blurEffect(style: .dark, alpha: 0.9)\n// transition.backgroundType = .color(UIColor.blue.withAlphaComponent(0.5))\n    \nalert.at.transition = transition\npresent(alert, animated: true, completion: nil)\n```\n\n## EasyTransition\n\nYou can easily compose your custom transition with a enum named **AnimationType**\n\n```swift\nlet alert = SomeController()\nlet transition = EasyTransition()\ntransition.startTransforms = [.rotation(angle: CGFloat(Double.pi/2), anchorPoint: CGPoint(x: 0, y: 0)), .alpha(0)]\nalert.at.transition = transition\npresent(alert, animated: true, completion: nil)\n```\n\nEasyTransition use **startTransforms** and final frame of presented controller's view, to calculate the state of start. The above sample code, the view will rotate pi / 2 with anchoPoint in left top corner, and alpha 0. \n\nThere is also a property named **endTransforms**, it will have same value with **startTransforms** in default.\n\nYou can also change duration, damping, velocity, curve of the animation with **presentAnimateParams** and **dismissAnimateParams**\n\n```swift\nlet alert = SomeController()\nlet transition = EasyTransition()\ntransition.presentAnimateParams.damping = 0.3\nalert.at.transition = transition\npresent(alert, animated: true, completion: nil)\n```\n\n## MenuTransition\n\nThere are only three steps to make a side menu. Set frame and change background just like other *AlertTransition*.\n\n```swift\nclass MainController: UIViewController {\n    // First, hold your menu controller in your main controller\n    var menuController = MenuController()\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        // second, initialize MenuTransition with presenting controller\n        let transition = MenuTransition(from: navigationController)\n        // third, set MenuTransition to your menuController\n        menuController.at.transition = transition\n    }\n}\n```\n\nWhen you select an item at side menu, you want to push a controller from main controller. Push like this to make suitable animation.\n\n```swift\n(self.at.transition as? MenuTransition)?.push(controller: NextViewController())\n```\n\n## Write custom AlertTransition\n\nIn most cases, you only need to override func **performPresentedTransition** and **performDismissedTransition**. Apply your animation to **presentingView** and **presentedView**, such as TrolleyTransition:\n\n```swift\npublic class TrolleyTransition: AlertTransition {\n\n    public override init(from controller: UIViewController?) {\n        super.init(from: controller)\n        duration = 0.5\n    }\n    \n    public override func performPresentedTransition(presentingView: UIView, presentedView: UIView, context: UIViewControllerContextTransitioning) {\n        presentedView.frame.origin.y = UIScreen.main.bounds.height\n        \n        UIView.animate(withDuration: duration/2, animations: {\n            presentingView.layer.transform = self.firstTransform()\n        }) { (complete) in\n            UIView.animate(withDuration: self.duration/2, animations: {\n                presentingView.layer.transform = self.secondTransform()\n                presentedView.transform = CGAffineTransform(translationX: 0, y: -presentedView.frame.height)\n            }, completion: { (complete) in\n                context.completeTransition(complete)\n            })\n        }\n    }\n    \n    public override func performDismissedTransition(presentingView: UIView, presentedView: UIView, context: UIViewControllerContextTransitioning) {\n        \n        UIView.animate(withDuration: duration/2, animations: {\n            presentedView.transform = CGAffineTransform.identity\n            presentingView.layer.transform = self.firstTransform()\n        }) { (complete) in\n            UIView.animate(withDuration: self.duration/2, animations: {\n                presentingView.layer.transform = CATransform3DIdentity\n            }, completion: { (complete) in\n                context.completeTransition(complete)\n            })\n        }\n    }\n    \n    private func firstTransform() -\u003e CATransform3D {\n        var form = CATransform3DIdentity\n        form.m34 = 1.0 / -900\n        form = CATransform3DScale(form, 0.9, 0.9, 1)\n        form = CATransform3DRotate(form, 15.0 * CGFloat(Double.pi)/180.0, 1, 0, 0)\n        form = CATransform3DTranslate(form, 0, 0, -100.0)\n        return form\n    }\n    \n    private func secondTransform() -\u003e CATransform3D {\n        var form = CATransform3DIdentity\n        form.m34 = firstTransform().m34\n        form = CATransform3DTranslate(form, 0, -20, 0)\n        form = CATransform3DScale(form, 0.9, 0.9, 1)\n        return form\n    }\n}\n```\n\nIf you want add UIPercentDrivenInteractiveTransition, or has custom UIPresentationController, set **interactionTransitionType** and **presentationControllerType** at init method.\n\n```swift\npublic override init(from controller: UIViewController? = nil) {\n    super.init(from: controller)\n    \n    interactionTransitionType = EasyPercentDrivenTransition.self\n    presentationControllerType = SomePresentationController.self\n}\n```\n\nIf you write an amazing custom transition, please submit a pull requests. We looking forward to accumulate custom transitions. And with AlertTransition, we can easily change from one custom transition to another.\n\n## Getting involved\n\n* If you **want to contribute** please feel free to **submit pull requests**, even if you find some spell error in README, because I am not good at English.\n* If you **have a feature request** please **open an issue**.\n* If you **found a bug** or **need help** please **check older issues before submitting an issue**.\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects.\n\nSpecify AlertTransition into your project's Podfile:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget '\u003cYour App Target\u003e' do\n  #Swift3\n  #pod 'AlertTransition', \"~\u003e 1.0.4\"\n  #Swift4\n  pod 'AlertTransition', \"~\u003e 2.1.0\"\nend\n```\n\nIf you only want EasyTransition, MenuTransition or TrolleyTransition, you can pod them alone like this:\n\n```ruby\npod 'AlertTransition/Easy', \"~\u003e 2.1.0\"\npod 'AlertTransition/Menu', \"~\u003e 2.1.0\"\npod 'AlertTransition/Trolley', \"~\u003e 2.1.0\"\n```\n\nThen run the following command:\n\n```sh\n$ pod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a simple, decentralized\ndependency manager for Cocoa.\n\nSpecify AlertTransition into your project's Carthage:\n\n```\ngithub \"loopeer/AlertTransition\" ~\u003e 2.1.0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopeer%2Falerttransition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopeer%2Falerttransition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopeer%2Falerttransition/lists"}