- Notifications
You must be signed in to change notification settings - Fork202
Now playing controller from Apple Music, Mail & Podcasts Apple's apps.
License
ivanvorobei/SPStorkController
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Controlleras in Apple Music, Podcasts and Mail apps. Help if you need customize height or suppport modal style in iOS 12.
Simple adding close button and centering arrow indicator. Customizable height. Using customTransitionDelegate.
Alert you can find inSPAlert project. It support diffrents presets, some animatable.
If you like the project, don't forget toput star ★ and follow me on GitHub:
Swift4.2 &5.0. Ready for use on iOS 10+
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrateSPStorkController into your Xcode project using CocoaPods, specify it in yourPodfile:
pod'SPStorkController'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrateSPStorkController into your Xcode project using Carthage, specify it in yourCartfile:
github "ivanvorobei/SPStorkController"TheSwift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrateSPStorkController into your Xcode project using Xcode 11, specify it inProject > Swift Packages:
https://github.com/ivanvorobei/SPStorkControllerIf you prefer not to use any of the aforementioned dependency managers, you can integrateSPStorkController into your project manually. PutSource/SPStorkController folder in your Xcode project. Make sure to enableCopy items if needed andCreate groups.
Create controller and call funcpresentAsStork:
import UIKitimport SPStorkControllerclassViewController:UIViewController{overridefunc viewDidAppear(_ animated:Bool){ super.viewDidAppear(animated)letcontroller=UIViewController()self.presentAsStork(controller)}}
If you want customize controller (remove indicator, set custom height and other), create controller and settransitioningDelegate toSPStorkTransitioningDelegate object. Usepresent ordismiss functions:
letcontroller=UIViewController()lettransitionDelegate=SPStorkTransitioningDelegate()controller.transitioningDelegate= transitionDelegatecontroller.modalPresentationStyle=.customcontroller.modalPresentationCapturesStatusBarAppearance=trueself.present(controller, animated:true, completion:nil)
Please, do not initSPStorkTransitioningDelegate like this:
controller.transitioningDelegate=SPStorkTransitioningDelegate()
You will get an error about weak property.
To set light status bar for presented controller, usepreferredStatusBarStyle property. Also setmodalPresentationCapturesStatusBarAppearance. See example:
import UIKitclassModalViewController:UIViewController{overridevarpreferredStatusBarStyle:UIStatusBarStyle{return.lightContent}}
PropertycustomHeight sets custom height for controller. Default isnil:
transitionDelegate.customHeight=350
PropertyshowCloseButton added circle button with dismiss action. Default isfalse:
transitionDelegate.showCloseButton=false
On the top of controller you can add arrow indicator with animatable states. It simple configure.PropertyshowIndicator shows or hides top arrow indicator. Default istrue:
transitionDelegate.showIndicator=true
Property ParameterindicatorColor for customize color of arrow. Default isgray:
transitionDelegate.indicatorColor=UIColor.white
PropertyhideIndicatorWhenScroll shows or hides indicator when scrolling. Default isfalse:
transitionDelegate.hideIndicatorWhenScroll=true
You can set always line or arrow indicator. SetindicatorMode:
transitionDelegate.indicatorMode=.alwaysLine
You can also configure events that will dimiss the controller.PropertyswipeToDismissEnabled enables dismissal by swipe gesture. Default istrue:
transitionDelegate.swipeToDismissEnabled=true
PropertytranslateForDismiss sets how much need to swipe down to close the controller. Work only ifswipeToDismissEnabled is true. Default is240:
transitionDelegate.translateForDismiss=100
PropertytapAroundToDismissEnabled enables dismissal by tapping parent controller. Default istrue:
transitionDelegate.tapAroundToDismissEnabled=true
PropertycornerRadius for customize corner radius of controller's view. Default is10:
transitionDelegate.cornerRadius=10
PropertyhapticMoments allow add taptic feedback for some moments. Default is.willDismissIfRelease:
transitionDelegate.hapticMoments=[.willPresent,.willDismiss]
The project uses a snapshot of the screen in order to avoid compatibility and customisation issues. Before controller presentation, a snapshot of the parent view is made, and size and position are changed for the snapshot. Sometimes you will need to update the screenshot of the parent view, for that use static func:
SPStorkController.updatePresentingController(modal: controller)
and pass the controller, which is modal and usesSPStorkTransitioningDelegate.
If the parent controller scrollings and you try to showSPStorkController, you will see how it froze, and in a second its final position is updated. I recommend before presentSPStorkController stop scrolling force:
scrollView.setContentOffset(self.contentOffset, animated:false)
You may want to add a navigation bar to your modal controller. Since it became impossible to change or customize the native controller in swift 4 (I couldn’t even find a way to change the height of the bar), I had to recreate navigation bar from the ground up. Visually it looks real, but it doesn’t execute the necessary functions:
import UIKitimport SPFakeBarclassModalController:UIViewController{letnavBar=SPFakeBarView(style:.stork)overridefunc viewDidLoad(){ super.viewDidLoad()self.view.backgroundColor=UIColor.whiteself.navBar.titleLabel.text="Title"self.navBar.leftButton.setTitle("Cancel", for:.normal)self.navBar.leftButton.addTarget(self, action: #selector(self.dismissAction), for:.touchUpInside)self.view.addSubview(self.navBar)}}
You only need to add a navigation bar to the main view, it will automatically layout. Use style.stork in init ofSPFakeBarView. Here is visual preview with Navigation Bar and without it:
To use it, you need to installSPFakeBar pod:
pod'SPFakeBar'
If you useUIScrollView (or UITableView & UICollectionView) on controller, I recommend making it more interactive. When scrolling reaches the top position, the controller will interactively drag down, simulating a closing animation. Also available close controller by drag down onUIScrollView. To do this, set the delegate and in the functionscrollViewDidScroll call:
func scrollViewDidScroll(_ scrollView:UIScrollView){SPStorkController.scrollViewDidScroll(scrollView)}
Working with a collections classes is not difficult. In theExample folder you can find an implementation. However, I will give a couple of tips for making the table look better.
Firstly, if you useSPFakeBarView, don't forget to set top insets for content & scroll indicator. Also, I recommend setting bottom insets (it optional):
tableView.contentInset.top=self.navBar.heighttableView.scrollIndicatorInsets.top=self.navBar.height
Please, also useSPStorkController.scrollViewDidScroll function in scroll delegate for more interactiveness with your collection or table view.
For confirm closing by swipe, tap around, close button and indicator useSPStorkControllerConfirmDelegate. Implenet protocol:
@objcpublicprotocolSPStorkControllerConfirmDelegate:class{varneedConfirm:Bool{get}func confirm(_ completion:@escaping(_ isConfirmed:Bool)->())}
and setconfirmDelegate property to object, which protocol impleneted. Functionconfirm call ifneedConfirm return true. PassisConfirmed with result. Best options useUIAlertController with.actionSheet style for confirmation.
If you use custom buttons, in the target use this code:
SPStorkController.dismissWithConfirmation(controller:self, completion:nil)
It callconfirm func and check result of confirmation. See example project for more details.
You can check events by implementSPStorkControllerDelegate and set delegate fortransitionDelegate:
transitionDelegate.storkDelegate=self
Delagate has this functions:
protocolSPStorkControllerDelegate:class{optionalfunc didDismissStorkBySwipe()optionalfunc didDismissStorkByTap()}
If need usingSPStorkController with storyboard, set classSPStorkSegue for transition setting in storyboard file. I will give the class code so that you understand what it does:
import UIKitclassSPStorkSegue:UIStoryboardSegue{publicvartransitioningDelegate:SPStorkTransitioningDelegate?overridefunc perform(){ transitioningDelegate= transitioningDelegate??SPStorkTransitioningDelegate() destination.transitioningDelegate= transitioningDelegate destination.modalPresentationStyle=.custom super.perform()}}
Open your storyboard, choose transition and open right menu. OpenAttributes Inspector and in Class section insertSPStorkSegue.
If you want to present modal controller onSPStorkController, please set:
controller.modalPresentationStyle=.custom
It’s needed for correct presentation and dismissal of all modal controllers.
Apple present inWWDC 2019 new modal presentation style -Sheets. It ready use Support interactive dismiss and work with navigations bars. Available since iOS 13. I will add more information when I study this in more detail. You can see presentationhere.
I love being helpful. Here I have provided a list of libraries that I keep up to date. For seevideo previews of libraries without install openopensource.ivanvorobei.by website.
I have libraries with native interface and managing permissions. Also available pack of useful extensions for boost your development process.
Подписывайся в телеграмм-канал, если хочешь получать уведомления о новых туториалах.
Со сложными и непонятными задачами помогут в чате.
Видео-туториалы выклыдываю наYouTube:
About
Now playing controller from Apple Music, Mail & Podcasts Apple's apps.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors7
Uh oh!
There was an error while loading.Please reload this page.



