In the same theme as this post:
ios13 UIPopoverViewController showing UITableViewController - Safe Area problems / Missing parts of table
But in my case, it is not especially a UITableViewControllerany any View Controller in a popover on the iPad has the same issue since iOS13.
I have no problem with overlapping content, just the border.
App screenshot
let popoverContent = self.storyboard!.instantiateViewController(withIdentifier: controllerName) as! SelectSceneViewController
popoverContent.preferredContentSize = CGSize(width: 700,height: 500)
let nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.popover
nav.navigationBar.barStyle = navbarStyle
nav.view.layer.cornerRadius = 10
nav.view.layer.borderColor = UIColor.white.cgColor
nav.view.layer.borderWidth = 2
let popover = nav.popoverPresentationController
popover?.sourceView = button
popover?.sourceRect = button.bounds
self.present(nav, animated: true, completion: nil)
I have found the answer. I have to implement my own UIPopoverBackgroundView.
Example: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch09p476popovers/ch22p751popovers/MyPopoverBackgroundView.swift
Andrew Shepard has implemented a great UIPopoverBackgroundView:
https://gist.github.com/andyshep/6240110
https://andyshep.org/2013/08/2013-08-10-implementing-drawrect-on-uipopoverbackgroundview/
Related
I am trying to create number pad in iPad using popover view controller. Everything is achieved but there is a shadow beneath the pop view. I tried to remove that shadow but nothing worked for me. Here is my code which presents pop over view in my view controller.
let vc = self.storyboard?.instantiateViewController(withIdentifier: "PopOverVC") as? PopOverVC
vc?.modalPresentationStyle = .popover
vc?.preferredContentSize = CGSize(width: 280, height: 425)
vc?.delegate = self
if let popoverPresentationController = vc?.popoverPresentationController {
popoverPresentationController.permittedArrowDirections = [.down, .up, .right, .left]
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = txtNumber.frame
popoverPresentationController.delegate = self
if let popoverController = vc {
present(popoverController, animated: false, completion: nil)
}
}
Can anybody help me removing the shadow? Thanks in advance!!
I know this is going to sound confusing but I am making a to-do app for iOS, what I want to do is when a user taps on the add button, instead of user going to another view controller to enter in the new tasks information, I want a little window to pop up in that same view controller where the user can then enter the information. Is their a way to do this?
If i am not wrong you are talking about modal presentation where a view would appear over another view as a popup. This is how it can be done:
let vc = UIStoryboard.storyboard(storyboard: .Vote).instantiateViewController(YourController.self)
under YourController use controller of the popup view
vc.modalPresentationStyle = .popover
let nav = UINavigationController(rootViewController: vc)
nav.modalPresentationStyle = UIModalPresentationStyle.popover
let popover = nav.popoverPresentationController
vc.preferredContentSize = CGSize(width: 280,height: 300) //use own height and width
vc.navigationController?.isNavigationBarHidden = true
popover!.delegate = self
popover!.sourceView = self.view
popover!.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY - 20,width: 0,height: 0)
popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
self.present(nav, animated: true, completion: nil)
this will make the view appear as a popup in your root view
I created simple popup in tableview however I do not know how to make the subview transparent, right now it is full black.
This is how I created the popup inside tableview cell button click:
let vc = self.storyboard?.instantiateViewController(withIdentifier: "RatingViewController") as! RatingViewController
vc.modalPresentationStyle = .popover
vc.preferredContentSize = CGSize(200, 100)
if let presentationController = vc.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = .up
presentationController.sourceView = self.view
presentationController.sourceRect = CGRect(0, 0, 50, 50)
self.present(vc, animated: true, completion: nil)
}
What should I do to make it transparent? My subview for the RatingViewController is white but for some reason it shows as black.
I have used UIVideoEditorViewController for trimming selected video. The problem is that the editorController has to be presented in popover style in iPad. When I running it on iPad, the editor view on pop over the left corner instead of the full screen. Is there any way to make the popover view in full screen size? Thanks
if UIVideoEditorController.canEditVideoAtPath(tmp) {
editVideoViewController = self.storyboard?.instantiateViewControllerWithIdentifier("editorVC") as! EditorViewController
editVideoViewController.delegate = self
editVideoViewController.videoPath = tmp
editVideoViewController.videoMaximumDuration = 30
editVideoViewController.videoQuality = .TypeHigh
editVideoViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
editVideoViewController.popoverPresentationController?.sourceView = editVideoViewController.view
self.presentViewController(editVideoViewController, animated: true, completion: nil)
}
There is no way to show UIVideoEditorController full screen. You can put it inside some container controller. And then configure this container controller preferredContentSize with screen bounds. You will get almost full-screen size popover.
let containerVC = UIViewController()
containerVC.preferredContentSize = UIScreen.main.bounds.size
containerVC.modalPresentationStyle = .popover
let ppc = containerVC.popoverPresentationController
ppc?.delegate = self
ppc?.sourceView = containerVC.view
ppc?.sourceRect = UIScreen.main.bounds
ppc?.permittedArrowDirections = .init(rawValue: 0 )
ppc?.canOverlapSourceViewRect = true
let videoController = UIVideoEditorController()
containerVC.addChild(videoController)
containerVC.view.addSubview(videoController.view)
videoController.didMove(toParent: containerVC)
self.present(containerVC, animated: true)
I'm presenting a Navigation Controller as a popover. First time a do it I can push to another View Controller with any issue. But, second time a present another controller the same way I can't perform a push because the self.navigationController of the presented Controller is nil. This is the piece of code I'm using to present the Controller
func instantiateEditController(view : UIView) -> UINavigationController
{
let popoverContent = self.storyboard?.instantiateViewControllerWithIdentifier("Edit Controller") as MCMEditController
popoverContent.preferredContentSize = CGSizeMake(320, 480)
let navController = MCMBaseNavigationController(rootViewController: popoverContent)
navController.modalPresentationStyle = UIModalPresentationStyle.Popover
navController.navigationBar.tintColor = UIColor.whiteColor()
let popover = navController.popoverPresentationController
popover?.sourceView = view
popover?.sourceRect = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)
return navController
}
Note: The Navigation Controller is always presented, but just the first time I perform pushes. And this code is for be used in iPad.
Because of the nature of Storyboards and not being able to show that here, I'm not sure where your issue is exactly.
However I successfully setup a project that works using segues. I changed your code to the following:
func instantiateEditController(view : UIView) -> UINavigationController
{
if let popoverContent = self.storyboard?.instantiateViewControllerWithIdentifier("Edit Controller") as? MCMEditController {
popoverContent.preferredContentSize = CGSizeMake(320, 480)
let navController = UINavigationController(rootViewController: popoverContent)
navController.modalPresentationStyle = UIModalPresentationStyle.Popover
navController.navigationBar.tintColor = UIColor.whiteColor()
let popover = navController.popoverPresentationController
popover?.sourceView = view
popover?.sourceRect = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)
return navController
} else {
return UINavigationController(rootViewController: self) // not recommend to keep this, I'm on Swift 1.2 and this was an easy fix to resolve the errors
}
}
To present this popover I set up this IBAction in my ViewController (sender in my case was a UIButton)
#IBAction func presentPopover(sender: AnyObject) {
if let view = sender as? UIView {
let controller = instantiateEditController(view)
let popover = UIPopoverController(contentViewController: controller)
popover.presentPopoverFromRect(view.frame, inView: self.view, permittedArrowDirections:UIPopoverArrowDirection.Any, animated: true)
}
}
The last thing that could be the issue is make sure your segues are using the segue type "show" for all the segues to make sure the transition between them use the navigation controller push:
Hope this helps!