{"id":13466409,"url":"https://github.com/m1entus/MZFormSheetPresentationController","last_synced_at":"2025-03-25T21:32:17.202Z","repository":{"id":33944949,"uuid":"37670749","full_name":"m1entus/MZFormSheetPresentationController","owner":"m1entus","description":"MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.","archived":false,"fork":false,"pushed_at":"2021-01-18T22:24:01.000Z","size":3501,"stargazers_count":972,"open_issues_count":26,"forks_count":146,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-18T13:32:02.960Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/m1entus.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-06-18T16:21:34.000Z","updated_at":"2024-12-26T10:03:54.000Z","dependencies_parsed_at":"2022-07-13T17:10:38.236Z","dependency_job_id":null,"html_url":"https://github.com/m1entus/MZFormSheetPresentationController","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1entus%2FMZFormSheetPresentationController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1entus%2FMZFormSheetPresentationController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1entus%2FMZFormSheetPresentationController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1entus%2FMZFormSheetPresentationController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m1entus","download_url":"https://codeload.github.com/m1entus/MZFormSheetPresentationController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040220,"owners_count":20551297,"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-07-31T15:00:43.695Z","updated_at":"2025-03-25T21:32:15.983Z","avatar_url":"https://github.com/m1entus.png","language":"Objective-C","funding_links":[],"categories":["Libs","UI","UI Components","Objective-C  Stars 1000以内排名整理","UI [🔝](#readme)","User Interface","Minor"],"sub_categories":["UI","Mobile","Sheet"],"readme":"[![](http://inspace.io/github-cover.jpg)](http://inspace.io)\n\nMZFormSheetPresentationController\n===========\n\n`MZFormSheetPresentationController` provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup controller size and feel form sheet.\n\n`MZFormSheetPresentationController` also has a number of predefined transitions so you can customize whether the modal form slides in, fades in, bounces in or you can create your own custom transition.  There are also a number of properties for customizing the exact look and position of the form. It support also pan gesture dismissing.\n\nThis project is continuation of [`MZFormSheetController`](https://github.com/m1entus/MZFormSheetController) which allow you to make form sheet when deployment target is set to \u003eiOS5 but use some tricky UIWindow hacks.\n\nHere are a couple of images showing `MZFormSheetPresentationController` in action:\n\n[![](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/animation2.gif)](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/animation2.gif)\n[![](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/animation1.gif)](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/animation1.gif)\n[![](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/screen2.png)](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/screen2.png)\n[![](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/screen1.png)](https://raw.github.com/m1entus/MZFormSheetPresentationController/master/Screens/screen1.png)\n\n## 2.x Change Log:\n* Fully tested and certified for iOS 9\n* Support for tvOS\n* Fixed issue with text size based on size class\n* Fixed autolayout issues\n* Added dissmisal pan gesture on each direction\n* Rewritten `MZFormSheetPresentationController` to use `UIPresentationController`\n* Support for adding shadow to content view\n* Added frame configuration handler which allow you to change frame during rotation and animations\n* Added `shouldCenterHorizontally` property\n* Allowed make your custom animator to support native transitions\n* Allow to make dynamic contentViewSize depents on displayed UIViewController\n\n## Upgrade from 1.x\n\nAs a major version change, the API introduced in 2.0 is not backward compatible with 1.x integrations. Upgrading is straightforward.\n* Use `MZFormSheetPresentationViewController` instead of `MZFormSheetPresentationController`\n\n* `MZFormSheetPresentationController` now inherits from `UIPresentationController` and manage presentation of popup\n\n* `MZFormSheetPresentationViewController` have property `presentationController` which allows you customization presented content view\n\n* `MZFormSheetPresentationController registerTransitionClass` is now `MZTransition registerTransitionClass`\n\n* `func entryFormSheetControllerTransition(formSheetController: MZFormSheetPresentationController, completionHandler: MZTransitionCompletionHandler)` changed to `func entryFormSheetControllerTransition(formSheetController: UIViewController, completionHandler: MZTransitionCompletionHandler)` which formSheetController frame is equal to contentViewSize with view origin.\n\n## Requirements\n\nMZFormSheetPresentationController requires either iOS 8.x and above.\n\n## Installation\n###[Carthage](https://github.com/Carthage/Carthage)\n\nAdd the following line to your `Cartfile`.\n\n```github \"m1entus/MZFormSheetPresentationController\" \"master\"```\n\nThen run `carthage update --no-use-binaries` or just `carthage update`. \n\nAfter building the framework you will need to add it to your project and import it using the Framework header:\n\n```#import \u003cMZFormSheetPresentationController/MZFormSheetPresentationControllerFramework.h\u003e```\n\nFor further details on the installation and usage of Carthage, visit [it's project page](https://github.com/Carthage/Carthage).\n\n\n###[CocoaPods](https://github.com/CocoaPods/CocoaPods)\n\nAdd the following line to your `Podfile`.\n\n```\n# Uncomment this line to define a global platform for your project\nplatform :ios, '8.0'\n# Uncomment this line if you're using Swift\nuse_frameworks!\n\ntarget 'ProjectName' do\n    pod 'MZFormSheetPresentationController'\nend\n```\n\nThen run `pod install --verbose` or just `pod install`. For details of the installation and usage of CocoaPods, visit [it's project page](https://github.com/CocoaPods/CocoaPods).\n\n## How To Use\n\nThere are two example projects, one is for Objective-C second is for Swift.\n\nLet's start with a simple example\n\nObjective-C\n``` objective-c\nUINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@\"formSheetController\"];\nMZFormSheetPresentationViewController *formSheetController = [[MZFormSheetPresentationViewController alloc] initWithContentViewController:navigationController];\nformSheetController.presentationController.contentViewSize = CGSizeMake(250, 250); // or pass in UILayoutFittingCompressedSize to size automatically with auto-layout\n\n[self presentViewController:formSheetController animated:YES completion:nil];\n```\n\nSwift\n```swift\nlet navigationController = self.storyboard!.instantiateViewController(withIdentifier: \"formSheetController\") as! UINavigationController\nlet formSheetController = MZFormSheetPresentationViewController(contentViewController: navigationController)\nformSheetController.presentationController?.contentViewSize = CGSize(width: 250, height: 250)  // or pass in UILayoutFittingCompressedSize to size automatically with auto-layout\n\nself.present(formSheetController, animated: true, completion: nil)\n```\n\nThis will display view controller inside form sheet container.\n\nIf you want to dismiss form sheet controller, use default dismissing view controller action.\n\nObjective-C\n```objective-c\n[self dismissViewControllerAnimated:YES completion:nil];\n```\n\nSwift\n```swift\nself.dismiss(animated: true, completion: nil)\n```\n\nEasy right ?!\n\n## Passing data\nIf you want to pass data to presenting view controller, you are doing it like normal. Just remember that IBOutlets are initialized after viewDidLoad, if you don't want to create additional properies, you can always use completion handler `willPresentContentViewControllerHandler` to pass data directly to outlets. It is called after viewWillAppear and before `MZFormSheetPresentationViewController` animation.\n\nObjective-C\n```objective-c\nMZFormSheetPresentationViewController *formSheetController = [[MZFormSheetPresentationViewController alloc] initWithContentViewController:navigationController];\n\nPresentedTableViewController *presentedViewController = [navigationController.viewControllers firstObject];\npresentedViewController.textFieldBecomeFirstResponder = YES;\npresentedViewController.passingString = @\"PASSSED DATA!!\";\n\nformSheetController.willPresentContentViewControllerHandler = ^(UIViewController *vc) {\n    UINavigationController *navigationController = (id)vc;\n    PresentedTableViewController *presentedViewController = [navigationController.viewControllers firstObject];\n    [presentedViewController.view layoutIfNeeded];\n    presentedViewController.textField.text = @\"PASS DATA DIRECTLY TO OUTLET!!\";\n};\n\n[self presentViewController:formSheetController animated:YES completion:nil];\n```\n\nSwift\n```swift\nlet formSheetController = MZFormSheetPresentationViewController(contentViewController: navigationController)\n\nlet presentedViewController = navigationController.viewControllers.first as! PresentedTableViewController\npresentedViewController.textFieldBecomeFirstResponder = true\npresentedViewController.passingString = \"PASSED DATA\"\n\nformSheetController.willPresentContentViewControllerHandler = { vc in\n    let navigationController = vc as! UINavigationController\n    let presentedViewController = navigationController.viewControllers.first as! PresentedTableViewController\n    presentedViewController.view?.layoutIfNeeded()\n    presentedViewController.textField?.text = \"PASS DATA DIRECTLY TO OUTLET!!\"\n}\n\nself.present(formSheetController, animated: true, completion: nil)\n```\n\n## Using pan gesture to dismiss\n\n```objective-c\ntypedef NS_OPTIONS(NSUInteger, MZFormSheetPanGestureDismissDirection) {\n    MZFormSheetPanGestureDismissDirectionNone = 0,\n    MZFormSheetPanGestureDismissDirectionUp = 1 \u003c\u003c 0,\n    MZFormSheetPanGestureDismissDirectionDown = 1 \u003c\u003c 1,\n    MZFormSheetPanGestureDismissDirectionLeft = 1 \u003c\u003c 2,\n    MZFormSheetPanGestureDismissDirectionRight = 1 \u003c\u003c 3,\n    MZFormSheetPanGestureDismissDirectionAll = MZFormSheetPanGestureDismissDirectionUp | MZFormSheetPanGestureDismissDirectionDown | MZFormSheetPanGestureDismissDirectionLeft | MZFormSheetPanGestureDismissDirectionRight\n};\n```\n```objective-c\nUINavigationController *navigationController = [self formSheetControllerWithNavigationController];\nMZFormSheetPresentationViewController *formSheetController = [[MZFormSheetPresentationViewController alloc] initWithContentViewController:navigationController];\n\nformSheetController.interactivePanGestureDissmisalDirection = MZFormSheetPanGestureDismissDirectionAll;\n\n[self presentViewController:formSheetController animated:YES completion:nil];\n\n```\n\n## Blur background effect\n\nIt is possible to display blurry background, you can set `MZFormSheetPresentationController` default appearance or directly to `MZFormSheetPresentationController`\n\nObjective-C\n```objective-c\n// Blur will be applied to all MZFormSheetPresentationControllers by default\n[[MZFormSheetPresentationController appearance] setShouldApplyBackgroundBlurEffect:YES];\n\nor\n\n// This will set to only one instance\nformSheetController.shouldApplyBackgroundBlurEffect = YES;\n```\n\nSwift\n```swift\n// Blur will be applied to all MZFormSheetPresentationControllers by default\nMZFormSheetPresentationController.appearance().shouldApplyBackgroundBlurEffect = true\n\nor\n\n// This will set to only one instance\nformSheetController.shouldApplyBackgroundBlurEffect = true\n```\n\n## Transitions\n\nMZFormSheetPresentationViewController has predefined couple transitions.\n\nObjective-C\n``` objective-c\ntypedef NS_ENUM(NSInteger, MZFormSheetPresentationTransitionStyle) {\n MZFormSheetPresentationTransitionStyleSlideFromTop = 0,\n MZFormSheetPresentationTransitionStyleSlideFromBottom,\n MZFormSheetPresentationTransitionStyleSlideFromLeft,\n MZFormSheetPresentationTransitionStyleSlideFromRight,\n MZFormSheetPresentationTransitionStyleSlideAndBounceFromTop,\n MZFormSheetPresentationTransitionStyleSlideAndBounceFromBottom,\n MZFormSheetPresentationTransitionStyleSlideAndBounceFromLeft,\n MZFormSheetPresentationTransitionStyleSlideAndBounceFromRight,\n MZFormSheetPresentationTransitionStyleFade,\n MZFormSheetPresentationTransitionStyleBounce,\n MZFormSheetPresentationTransitionStyleDropDown,\n MZFormSheetPresentationTransitionStyleCustom,\n MZFormSheetPresentationTransitionStyleNone,\n};\n```\n\nIf you want to use them you will have to just assign `contentViewControllerTransitionStyle` property\n\nObjective-C\n``` objective-c\nformSheetController.contentViewControllerTransitionStyle = MZFormSheetPresentationTransitionStyleFade;\n```\n\nYou can also create your own transition by implementing `MZFormSheetPresentationViewControllerTransitionProtocol` protocol and register your transition class as a custom style.\n\nObjective-C\n``` objective-c\n@interface CustomTransition : NSObject \u003cMZFormSheetPresentationViewControllerTransitionProtocol\u003e\n@end\n\n[MZTransition registerTransitionClass:[CustomTransition class] forTransitionStyle:MZFormSheetTransitionStyleCustom];\n\nformSheetController.contentViewControllerTransitionStyle = MZFormSheetTransitionStyleCustom;\n```\n\nSwift\n```swift\nclass CustomTransition: NSObject, MZFormSheetPresentationViewControllerTransitionProtocol {\n}\n\nMZTransition.registerClass(CustomTransition.self, for: .custom)\n\nformSheetController.contentViewControllerTransitionStyle = .custom\n```\n\nif you are creating own transition you have to call completionBlock at the end of animation.\n\nObjective-C\n```objective-c\n- (void)exitFormSheetControllerTransition:(nonnull UIViewController *)presentingViewController\n                        completionHandler:(nonnull MZTransitionCompletionHandler)completionHandler {\n    CGRect formSheetRect = presentingViewController.view.frame;\n    formSheetRect.origin.x = [UIScreen mainScreen].bounds.size.width;\n\n    [UIView animateWithDuration:0.3\n                          delay:0\n                        options:UIViewAnimationOptionCurveEaseIn\n                     animations:^{\n                         presentingViewController.view.frame = formSheetRect;\n                     }\n                     completion:^(BOOL finished) {\n                         completionHandler();\n                     }];\n}\n```\n\nSwift\n```swift\nfunc exitFormSheetControllerTransition(_ presentingViewController: UIViewController, completionHandler: @escaping MZTransitionCompletionHandler) {\n    var formSheetRect = presentingViewController.view.frame\n    formSheetRect.origin.x = UIScreen.main.bounds.width\n\n    UIView.animate(withDuration: 0.3, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {\n        presentingViewController.view.frame = formSheetRect\n    }, completion: {(value: Bool)  -\u003e Void in\n        completionHandler()\n    })\n}\n```\n\n## Transparent Touch Background\n\nIf you want to have access to the controller that is below MZFormSheetPresentationController, you can set property `transparentTouchEnabled` and background view controller will get all touches.\n\nObjective-C\n```objective-c\nMZFormSheetPresentationViewController *formSheetController = [[MZFormSheetPresentationViewController alloc] initWithContentViewController:viewController];\nformSheetController.presentationController.transparentTouchEnabled = YES;\n```\n\nSwift\n```swift\nlet formSheetController = MZFormSheetPresentationViewController(contentViewController: viewController)\nformSheetController.presentationController?.isTransparentTouchEnabled = true\n```\n\n## Completion Blocks\n\n``` objective-c\n/**\n The handler to call when presented form sheet is before entry transition and its view will show on window.\n */\n@property (nonatomic, copy, nullable) MZFormSheetPresentationViewControllerCompletionHandler willPresentContentViewControllerHandler;\n\n/**\n The handler to call when presented form sheet is after entry transition animation.\n */\n@property (nonatomic, copy, nullable) MZFormSheetPresentationViewControllerCompletionHandler didPresentContentViewControllerHandler;\n\n/**\n The handler to call when presented form sheet will be dismiss, this is called before out transition animation.\n */\n@property (nonatomic, copy, nullable) MZFormSheetPresentationViewControllerCompletionHandler willDismissContentViewControllerHandler;\n\n/**\n The handler to call when presented form sheet is after dismiss.\n */\n@property (nonatomic, copy, nullable) MZFormSheetPresentationViewControllerCompletionHandler didDismissContentViewControllerHandler;\n```\n\n## Autolayout\n\nMZFormSheetPresentationController supports autolayout.\n\n## Storyboard\n\nMZFormSheetPresentationController supports storyboard.\n\nMZFormSheetPresentationViewControllerSegue is a custom storyboard segue which use default MZFormSheetPresentationController settings.\n\nIf you want to get acces to form sheet controller and pass data using storyboard segue, the code will look like this:\n\nObjective-C\n```objective-c\n- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {\n    if ([segue.identifier isEqualToString:@\"segue\"]) {\n        MZFormSheetPresentationControllerSegue *presentationSegue = (id)segue;\n        presentationSegue.formSheetPresentationController.presentationController.shouldApplyBackgroundBlurEffect = YES;\n        UINavigationController *navigationController = (id)presentationSegue.formSheetPresentationController.contentViewController;\n        PresentedTableViewController *presentedViewController = [navigationController.viewControllers firstObject];\n        presentedViewController.textFieldBecomeFirstResponder = YES;\n        presentedViewController.passingString = @\"PASSSED DATA!!\";\n    }\n}\n```\n\nSwift\n```swift\noverride func prepare(for segue: UIStoryboardSegue, sender: Any?) {\n    if let identifier = segue.identifier {\n        if identifier == \"segue\" {\n            let presentationSegue = segue as! MZFormSheetPresentationViewControllerSegue\n            presentationSegue.formSheetPresentationController.presentationController?.shouldApplyBackgroundBlurEffect = true\n            let navigationController = presentationSegue.formSheetPresentationController.contentViewController as! UINavigationController\n            let presentedViewController = navigationController.viewControllers.first as! PresentedTableViewController\n            presentedViewController.textFieldBecomeFirstResponder = true\n            presentedViewController.passingString = \"PASSED DATA\"\n        }\n    }\n}\n```\n\n## ARC\n\nMZFormSheetPresentationController uses ARC.\n\n## App Extensions\n\nSome position calculations access [UIApplication sharedApplication] which is not permitted in application extensions. If you want to use MZFormSheetPresentationController in extensions add the MZ_APP_EXTENSIONS=1 preprocessor macro in the corresponding target.\n\nIf you use Cocoapods you can use a post install hook to do that:\n```ruby\npost_install do |installer|\n    installer.pods_project.targets.each do |target|\n        if target.name == \"MZFormSheetPresentationController\"\n            target.build_configurations.each do |config|\n                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']\n                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] \u003c\u003c 'MZ_APP_EXTENSIONS=1'\n            end\n        end\n    end\nend\n```\n\n## Contact\n\n[Michal Zaborowski](http://github.com/m1entus)\n\n[Twitter](https://twitter.com/iMientus)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm1entus%2FMZFormSheetPresentationController","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm1entus%2FMZFormSheetPresentationController","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm1entus%2FMZFormSheetPresentationController/lists"}