Transition between different presentation styles for a UIViewController using swift - ios

I'm trying to create an affect where I present a UIViewController as a popover and then animate that view controller into a few different modal presentation styles.
I have successfully presented the view as a popover, and then after dismissing the view re presented it as a full screen overlay but I'm having trouble finding a workflow that allows me to transition without first dismissing the view controller.
I've included an illustration below showing the kind of effect I'd like to achieve where a single view controller transitions between 3 presentation styles, A, B, & C without being dismissed.
In the illustration A represents a popover modal presentation style, B custom, and C fullScreen
It's worth noting that these particular modal presentation styles are not important, rather that I would like to be able to transition between many kind of modal presentation style for a single view controller without first dismissing it.
What would be the best way to approach this kind of transition?

Related

Present a UIViewController with active background

There is a view controller (B), which presents as a half-screen modal with a custom presentation style and animation. I present this on a button tap on the main view controller (A), and dismiss with a close button on modal. When this modal is presented I want to access background view (A) buttons too. But when I inspect there is a TransitionView between the modal (B) and the background view (A).
Is there anyway to achieve this by presenting B as a modal on top of A? Or is there any other approach to show both A and B together & keep both active?
Yes it's possible, for modal presentation you have to use UIPresentationController and set shouldRemovePresentersView = false and implement UIViewControllerAnimatedTransitioning to perform the actual animation.
Alternatively you can use UISplitViewController with overlay presentation style, which then will take care of animations and layout for you.

Swift Full Screen Navigation Push Segue

I want to achieve something similar to Facebook's way of presenting the comments view controller for a specific post. In below picture one can see, that the pushed new view controller is presented "full screen" (for the lack of a better way of describing the behaviour). It seems to me like some kind of modal segue rather than a push one. When trying to recreate that in my own app I can't achieve that the whole navigation bar is included in the presentation segue. Only the view inside the presentation hierarchy is changed. I want the second view controller to be entirely white (the view as well as the navigation bar) but both view controllers should have the default swipe-to-go-back behaviour. How can that be done?
What they're probably doing is hiding the navigation bar.
You can achieve the same effect if you set navigationController?.navigationBar.isHidden = true (can also do it on navigation bar in UINavigationController from the storyboard), make a regular show segue and just display it using performSegue(withIdentifier: "nextScreen", sender: nil). You can then make your own UI logic for displaying back buttons etc.

With a custom navigation controller push transition, how do I have the previous view controller behind like modal presentations?

When performing a custom modal view controller transition, the view controller you're coming from sits behind the new one nicely (think of Apple's "form sheet" style presentation on an iPad for instance), and when you rotate the device the previous view controller visible in the back rotates as well.
I'm unsure how to get this functionality with a UINavigationController custom push animation. It seems it isn't expected for the previous view controller to be visible from behind and it isn't.
I could take a screenshot, but it won't update on landscape rotation.
How is it done so easily with a modal transition and how do I replicate that for navigation controller custom transitions?
As far as I understand the UINavigationController class such functionality cannot be achieved through it.
UINavigationController is a container controller, which can show only one VC within it at a time. It keeps all the VCs in the stack, but not their views (views are kept by VCs themselves).
Unlike it, the modal presentation is a special type of VC-presentation, and it's not limited by the container-functionality.

What's the difference between all the Selection Segues?

Show
Show Detail
Present Modally
Popover presentation
Custom
What is the difference between them? I couldn't find any documentation on it. There used to be some which I found in a Google search, but it's now gone: https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-storyboard/StoryboardSegue.html
Here is a quick summary of the segues and an example for each type.
Show - Pushes the destination view controller onto the navigation stack, sliding overtop from right to left, providing a back button to return - if not embedded in a navigation controller it will be presented modally
Example: Navigating in Settings, for example tapping General > About
Show Detail - For use in a split view controller, replaces the secondary view controller when in a multi-column interface, or if collapsed to one column it will push in the navigation controller
Example: In Messages, tapping a conversation will show the conversation details - replacing the view controller on the right when in a two column layout, or push the conversation when in a single column layout
Present Modally - Presents a view controller overtop the current view controller in various fashions as defined by the modal presentation and transition style - most commonly used to present a view controller in a sheet that animates up from the bottom
Example: Selecting Face ID & Passcode in Settings
Popover Presentation - When run on iPad, the destination appears in a popover, and tapping anywhere outside will dismiss it - popovers are supported on iPhone as well but by default it will present the view controller modally
Example: Tapping the + button in Calendar
Custom - You may implement your own custom segue and have control over its behavior
Embed - You may embed a view controller into another view controller, such as navigation, tab bar, and split view controllers as well as custom containers
Unwind - You may use an unwind segue to navigate back to a previous view controller, even if there’s many screens pushed/presented on top all of them will be dismissed
The deprecated segues are essentially the non-adaptive equivalents of those described above. These segue types were deprecated in iOS 8: Push, Modal, Popover, Replace.
For more info, you may read over the Using Segues documentation which also explains the types of segues and how to use them in a Storyboard. Also check out Session 216 Building Adaptive Apps with UIKit from WWDC 2014. They talked about how you can build adaptive apps using these new Adaptive Segues, and they built a demo project that utilizes these segues.
For clarity, I'd like to illustrate #Joey's answer above with these gifs :
Show
Show Detail
Present Modally
Present As Popover
The document has moved here it seems: https://help.apple.com/xcode/mac/8.0/#/dev564169bb1
Can't copy the icons here, but here are the descriptions:
Show: Present the content in the detail or master area depending on the content of the screen.
If the app is displaying a master and detail view, the content is pushed onto the detail area. If the app is only displaying the master or the detail, the content is pushed on top of the current view controller stack.
Show Detail: Present the content in the detail area.
If the app is displaying a master and detail view, the new content replaces the current detail. If the app is only displaying the master or the detail, the content replaces the top of the current view controller stack.
Present Modally: Present the content modally.
Present as Popover: Present the content as a popover anchored to an existing view.
Custom: Create your own behaviors by using a custom segue.
For those who prefer a bit more practical learning, select the segue in dock, open the attribute inspector and switch between different kinds of segues (dropdown "Kind"). This will reveal options specific for each of them: for example you can see that "present modally" allows you to choose a transition type etc.

Can I move from a login View to a SplitView in an iPad application?

Hope there is not an answer yet (I've checked). Can I introduce a login View in my application that enables a SplitView by using a button or something?
I've checked MGSplitViewController, but I'd like to use something more light and minimal.
If it's not possible, can I introduce a login View in my DetaiView that enables a TableView?
You can transition between arbitrary view controllers in iOS. The usual ways are using modal presentation (I like to present splash screens with a cross-dissolve animation to the root view controller of the app), or pushing/popping with navigation controllers. You can also programatically swap between multiple views in a view controller via setting the "view" property.

Resources