I want to implement a bottom sheet as per the image. The bottom will have a pan gesture to pull up and down
What I am confused about is :
If, I choose the second option how would I update window on pan?
You should not create a new UIWindow
. Generally an iOS app has just 1 window. The two best options I see are:
You can add a subview and gesture recognisers to implement pulling. That means that all the logic will probably be within the parent UIViewController
. If there is not much logic, and the sheet does not have to be reusable, this is a good option.
If there is more logic inside the sheet, or the sheet has the be reusable, then it would be better to create a separate UIViewController
for this. You can then present this using a custom animation and a presentation controller. Look into UIViewControllerAnimatedTransitioning
and UIPresentationController
for this.
I have used the second option before. A UIPresentationController
take care of positioning the sheet view on the bottom of screen. It also dims the background, and attaches gesture recognisers to handle pulling and dismissing.
You can use this tutorial to get started with a UIPresentationController
. You can also take the code from there and adapt it to your needs: https://www.raywenderlich.com/915-uipresentationcontroller-tutorial-getting-started