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.
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 am NOT USING StoryBoard in my project. I have presented one view controller as popOver Style.
let vcOne = ViewControllerOne()
vcOne.showCorrectionFactor = true
vcOne.modalPresentationStyle = .popover
let pop = vcOne.popoverPresentationController
pop?.sourceView = self.view
pop?.sourceRect = sender.frame
vcOne.preferredContentSize = CGSize(width: 400, height: 500)
self.present(vcOne, animated: true, completion: nil)
Now i want to navigate to other view controller from ViewControllerOne() and with in this pop up.
I am doing it like
let vc = PairViewController()
self.navigationController?.pushViewController(vc, animated: true)
But self.navigationController? is getting nil value. How can i achieve this without story board.
You did not embed ViewControllerOne in a UINavigationController, so of course self.navigationController is nil.
Just do this:
// embed it!
let navController = UINavigationController(rootViewController: vcOne)
// get the popover presentation controller from the navigation controller!
let pop = navController.popoverPresentationController
pop?.sourceView = self.view
pop?.sourceRect = sender.frame
vcOne.preferredContentSize = CGSize(width: 400, height: 500)
// present navController rather than vcOne!
self.present(navController, animated: true, completion: nil)
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/
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)
This what I use to present popover:
func presentPopoverController(controller: UIViewController, fromView view: UIView) {
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
controller.preferredContentSize = CGSizeMake(400, 400)
let popover = controller.popoverPresentationController
popover?.permittedArrowDirections = .Any
print(view.frame)
popover?.sourceView = view
popover?.sourceRect = view.frame //***
presentViewController(controller, animated: true, completion: nil)
}
This is how it looks on screen:
And this is output on console:
(326.0, 15.0, 63.0, 10.0)
If I remove the line with ***then it looks like following, and is still in wrong place:
Output on console is same as above.
There should be popover?.sourceRect = view.bounds instead of view.frame.