Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present commit view controller modally instead of pushing when using 3D Touch Peek & Pop

I have an app that allows users to view photos in a UICollectionViewController that's embedded inside a UINavigationController. When the user taps to view a photo, I present a new view controller modally over full screen (not the default Full Screen). I now want to implement a 3D Touch commit (pop) view controller to appear exactly as it does when the user just taps the photo. The problem is, when popping into the full screen photo, iOS behind the scenes is pushing this view controller on the stack - the navigation bar is still visible and it adds a back button to go back to the previous screen. I don't want that, I want the commit view controller to be presented modally.

I noticed if I remove the navigation controller, iOS will present the commit view controller modally instead of pushing. But I cannot remove my navigation controller, and it's still just presented full screen not over full screen.

How can I change the default behavior so that the commit view controller is presented modally Over Full Screen instead of pushed onto the stack when the originating view controller is embedded inside a navigation controller?

I've tried to set the modalPresentationStyle to .OverFullScreen when I configure the commit view controller in previewingContext:commitViewController:. This did not appear to make any difference.

The current behavior is a problem for a few reasons:
- I present over the full screen so that the underlying view controller is still visible underneath, blurred out. When it's pushed this effect cannot be achieved.
- I present the full screen photo using a custom transition using UIViewControllerTransitioningDelegate, and it transitions upon dismiss as well. When dismissing this after a push, it only performs the default pop animation instead of my custom animation.

like image 716
Jordan H Avatar asked Feb 08 '23 03:02

Jordan H


1 Answers

Figured it out! Just set the modalPresentationStyle to .OverFullScreen, and very importantly, instead of calling showViewController in previewingContext:commitViewController:, call presentViewController. Simple. Can't believe I didn't see that before posting. :)

like image 150
Jordan H Avatar answered Feb 10 '23 23:02

Jordan H