Present Modal View in Detail View in UISplitViewController - ios

I want to make a behavior like contacts app in iPad with landscape mode.
I'm expecting that a Modal shows in a Detail view when I click upper right add button.
but now if I click upper right add button, the Modal shows in all screen.
what method should I use? showDetailViewController? or presentViewController? I don’t know how to show Modal in only Detail View.

Firstly you need to set detail view controller's property definesPresentationContext = true. So now it defines presentation context. By default view controllers doesn't pay attention to the current context when they are presented therefore you must do viewController.modalPresentationStyle = .CurrentContext
That's how complete method looks like
func adaptivePresentViewController(viewController: UIViewController) {
let detailVC = splitViewController!.viewControllers[1]
detailVC.definesPresentationContext = true
viewController.modalPresentationStyle = .CurrentContext
detailVC.presentViewController(viewController, animated: true, completion: nil)
}

Related

Page views not correctly sized after segue

I recently updated my XCode to version 11.0. Ever since the update segues on an old project have been behaving weirdly. When I segue modally to a new page the page does not fill the entire screen and seemingly hovers instead.
Here is a picture of the view:
https://imgur.com/dAxEr4q
I would like for the pages to take up the full length of the device screen as they did prior to the upgrade.
Thanks in advance for any assistance.
This has to do with the new default modal presentation style in iOS 13.
To set the prior behavior, you need to change the presentation style to full screen.
You can do this both in storyboard by editing your segue's Presentation attribute and setting it from Automatic to Full Screen:
Alternatively, if you are presenting your View Controller programmatically, you can set your View Controllers modalPresentationStyle before presenting it, like so:
let detailController = /* your View Controller */
detailController.modalPresentationStyle = .overFullScreen
present(detailController, animated: true, completion: nil)
So the solution turned out to be more obvious than I realized. If you click on the segue symbol on the storyboard some options are displayed in the side bar.
Selecting presentation -> full screen from the drop down fixed my issue.
Adding a screenshot for clarity: https://imgur.com/BRCbx5k
Hope this helps anyone else having segue problems :)
You can programmatically present the controller like in below code :
let vc = secondStoryBoard.instantiateViewController(withIdentifier: "SearchNavVC")
vc.modalPresentationStyle = .fullScreen
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true, completion: nil)

Swift - Without storyboard , how do I make a modal popup?

I didn't use a storyboard and I'm having trouble finding resources on programmatically making a modal popup ( it'll be a form with white background that takes up the bottom half of the screen) after you press a button. The previous view would be disabled until you exit out of this modal popup.
Would this modal popup have its own view and view controller? How would I make the popup appear and after you exit, you give the control back to the original view controller?
Thanks?
let rateViewController = RatePopupVC()
rateViewController.modalTransitionStyle = .crossDissolve
rateViewController.modalPresentationStyle = .overCurrentContext
rateViewController.item = item // In case you want to transfer some data
self.present(rateViewController, animated: true, completion: nil)
Would this modal popup have its own view and view controller
Yes. Configure your view controller and its view, and present it with present and dismiss it with dismiss. You can add custom transition animation and custom positioning of the view.

Present ViewController over current context but the presenting View controller should take control of user interraction

I am presenting a bottom banner over the current context:
self.bottomViewController.modalPresentationStyle = .overCurrentContext
self.present(self.bottomViewController, animated: true, completion:{
self.addChildViewController(self.bottomViewController)
self.bottomViewController.didMove(toParentViewController: self)
})
After presenting the modal view controller, I want the parent to still receive the touch events and takes control.
For some reasons I can't use the containment (add the view as subview and then animate the presentation)

Edit button not displayed in UITabBarController's MoreNavigationController

A UITabBarController is being pushed onto the stack:
let presenter = presentingViewController as! UINavigationController
let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
presenter.pushViewController(tabvc, animated: true)
Once presented the more tab button correctly shows, but the edit button to rearrange the tab bars does not. According to the docs on the MoreNavigationController:
The interface for the standard More item includes an Edit button that
allows the user to reconfigure the tab bar. By default, the user is
allowed to rearrange all items on the tab bar. If you do not want the
user to modify some items, though, you can remove the appropriate view
controllers from the array in the customizableViewControllers
property.
My guess is that the tab bar is not happy being in a navigation controller. Any ideas on bringing the edit button back?
You can have both a UINavigationController and a UITabBarController ; using Storyboard helps understand the issue better, any of these solutions will work:
Start out with a UITabBarController as initial view controller
Use presentViewController instead of pushViewController
Use a modal Storyboard segue to perform a modal presentation
Swap out the rootViewController dynamically
Initial View Controller Design
When the Tab Bar Controller is initial View Controller, the Edit button is displayed normally.
Pushed Design
Another Navigation Controller is initial View Controller, using one of 5 adaptive Action Segue:
Show
Custom
-> No Edit button, since it is in direct conflict with the parent UITableViewController.
Show Detail
Present Modally
Popover Presentation
-> Edit button displayed as expected.
Code
1. Program Modal
Using the exact code presented in the question, change the last line:
let presenter = presentingViewController as! UINavigationController
let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
presenter.presentViewController(tabvc, animated: true, completion: nil)
2. Storyboard Modal
keeping with the Storyboard theme, create a segue of the correct type, assign an identifier (i.e. presentModallySegue) and the 5 lines above become this single line:
self.performSegueWithIdentifier("presentModallySegue", sender: self)
3. root Swap
A more drastic solution involves swapping out the root view controller at the window level:
let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
self.view.window!.rootViewController = tabvc
Conclusion
Either change your design to adopt the Tab Bar Controller as the initial View Controller, or present the Tab Bar Controller modally.
The reason is that navigation bar of your presenter overlaps with the navigation bar of More section.
If you don't show the navigation bar for you navigation controller, you will be able to see the Edit button again when you tap on the More tab.

Proper way to present UIActivityViewController inside UINavigationController inside popup

Suppose I have a UINavigationController inside a UIPopup. From there, I try to present a UIActivityViewController, by pushing it into the view controller.
if let navigationController = self.navigationController{
navigationController.pushViewController(activityViewController, animated: true)
}else{
self.presentViewController(activityViewController, animated: true, completion: nil)
}
The code executes without errors, however:
The displayed UIActivityViewController is corrupted and some text is not visible. (See image)
While pushing the view, part of the screen flashes when the popup resizes to accommodate the view (the popover is in the right side of the screen, and a ~150px vertical strip becomes brighter on the left)
As far as I know, I do not break Apple's Human Interface Guidelines by presenting the view this way. If so, what can be done so the view displays flawlessly?

Resources