0

I am working on an iOS project using UIKit, and I am implementing a UISheetPresentationController. My goal is to keep the sheet fixed on the current page. However, when I navigate to a new page (e.g., pushing a new UIViewController), I want the sheet to stay hidden in the background and not be visible on the new page. Essentially, I want the sheet to be tied to the current page and not appear or interfere with the navigation flow to other pages.

How can I achieve this behavior? Is there a specific way to control the visibility of UISheetPresentationController when navigating between pages in a UIKit project? Any suggestions or best practices would be greatly appreciated.

I'm attaching a sample video for reference.

enter image description here

1 Answer 1

0

I want the sheet to stay hidden in the background

You can't. When the user taps Go To Third View, dismiss the sheet before pushing the third view onto the navigation controller. The simplest way is to implement viewWillDisappear:

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    dismiss(animated: true)
}

In any case the thing you are imagining makes no sense. It is meaningless to "keep" the presented view over the first view controller when pushing, because pushing means that the first view controller is taken out of the view controller hierarchy — and you cannot present from a view controller that is not in the view controller hierarchy.

If you really really want the sort of interface you are imagining, then you will have to devise a subview belonging to the view of the first controller, that slides up and can be repositioned by the user, similar to the way a UISheetPresentationController's view looks and behaves, but not using a UISheetPresentationController or any sort of presented view controller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.