Resize a PopOver View Controller - ios

I have a view controller that I want to present as a popover. How can I change its size?
let carsViewController = CarsViewController()
carsViewController.modalPresentationStyle = .Popover
if let popoverPresentationController = a carsViewController.popoverPresentationController {
popoverPresentationController.permittedArrowDirections = .Up
popoverPresentationController.sourceView = carsButton
presentViewController(alertsViewController, animated: true, completion: nil)
}

It took me some time but I finally found an answer to this. It is as simple as adding the following line after initialising the view controller.
carsViewController.preferredContentSize = CGSize(width: 220,height:90)

Related

Get rid of shadow form popover view controller (Swift)

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!!

PUSH to ViewController from other viewcontroller which is presented as popover - WITHOUT STORY BOARD

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)

How to adjust the size of presented view - Swift 5 (Xcode)

I have a button which will lead a to collection view controller drawDetails_VC.
func showController() {
let drawDetails_VC = DrawDetails(collectionViewLayout: UICollectionViewFlowLayout())
navigationController?.navigationBar.tintColor = UIColor.white
let navController = CustomNavigationController(rootViewController: drawDetails_VC)
present(navController, animated: true, completion: nil)
}
After updating to Swift 5, the presented collection view Page Sheet is not covering the full screen.
I tried hours but didn't get what I want.
How can the presented sheet Page Sheet cover the whole screen and not as above image.
And how can I get programmaticlly the width of the presented Controller Page Sheet
Set your view controller's modal presentation style to .fullScreen or .overFullScreen. Try the code example below.
func showController() {
let drawDetails_VC = DrawDetails(collectionViewLayout: UICollectionViewFlowLayout())
navigationController?.navigationBar.tintColor = .white
let navController = CustomNavigationController(rootViewController: drawDetails_VC)
navController.modalPresentationStyle = .fullScreen
present(navController, animated: true, completion: nil)
}

How to display UIVideoEditorViewController full screen in iPad

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)

Presented popover controller appears in wrong place

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.

Resources