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?
Related
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)
On the click of a next button(which is in the cart view which in the image is hidden due to the view presented), I'm presenting a view modally. In iPhone, it looks like so....
On the click of that next button to present the view modally this is the code written...
let vc = PresentedUserDetailsViewController()
vc.modalPresentationStyle = .custom
present(vc, animated: true, completion: nil)
And in the PresentedUserDetailsViewController which is the presented view, I have initialized the following...
let menuHeight = UIScreen.main.bounds.height / 2
init() {
super.init(nibName: nil, bundle: nil)
modalPresentationStyle = .custom
transitioningDelegate = self
}
But when I run in an iPad Air 2 simulator the view is presented like so...
What should be done to make the presented view appear as in an iPhone..?
This seems like auto-layout issue. Maybe you could start by setting the Devices to universal in the general settings, so it will be fullscreen like so:
I can see that the button "From contacts" is not fully centered on the iPad screen. Maybe you have used fixed values for the layout? In that case you should use the "Center horizontally in container" constraint instead and generally set the width and height constraints relative to the safe area. Have you tried on a different screen like the iPhone 5? You might also see some issues there.
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.
Let's assume we want to show some popup view on our screen. When user clicks a button our view pops up. In popup view we have Close button that hide/remove view itself.
Which method should I use to do that kind of thing:
1.) After click on the button add popup view to my main view. Close button removes popup view from superview.
or
2.) Make popup view with alpha = 0 and after click a button change alpha = 1. Close button changes alpha to 0.
When I was adding and removing view by multiple clicking in buttons I have noticed that application started to slow down.
If you know good solution/method to do that kind of things (show view/views in another view) it would be very usefull.
Actually UIKit treats very-low alpha elements as hidden but hidden elements still participate in autoresizing and other layout operations associated with the view hierarchy. To save your performance i'd recommend to use addSubview/removeFromSuperview methods when show/hide your view.
You can also use ViewControllers with standard animation like:
let presentedVC: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("presentedVC") as ViewController
presentedVC.modalPresentationStyle = .OverCurrentContext
presentedVC.view.backgroundColor = UIColor.clearColor()
self.presentViewController(presentedVC, animated: true, completion: nil)
and when you tap Close inside your presentedVC use:
self.dismiss(animated: true, completion: nil)
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)
}