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)
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!!
According to the material.io documentation, the Modal Navigation Drawer should be used for sideMenus on mobile device but their api almost only contain drawers for the bottom, MDCBottomDrawerViewController, MDCBottomDrawerPresentationController etc. What about the side drawer? I checked but didn't find a MDCSideDrawerViewController.
The following code uses the MDCBottomDrawerViewController, but the problem is that the MDCBottomDrawerViewController().contentViewController presents my table from the botton instead of the from the side.
Set up for bottomDrawVC:
var bottomDrawerViewController: MDCBottomDrawerViewController = {
let drawer = MDCBottomDrawerViewController()
drawer.isTopHandleHidden = false
drawer.dismissOnBackgroundTap = true
return drawer
}()
The presenting of the bottomDrawVC:
#IBAction func toggleSideMenu() {
let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "TableViewController")
let size = CGSize(width: view.frame.width, height: view.frame.height)
bottomDrawerViewController.contentViewController?.preferredContentSize = size
bottomDrawerViewController.contentViewController = vc
present(bottomDrawerViewController, animated: true, completion: nil)
}
As I can't seem to find info in the docs, how does one present a modal side menu with material.io on iOS?
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 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)
In my app there is the need for a popover element, that displays the full description.
There is a normal UITextView in the UIViewController that displays the first 4 lines of the description. Now when the user clicks on that description the full description must be displayed. This will be done with the popover control recently introduced for the iPhone.
At the moment everything works, except for the fact that I want the popover to have a height that is exactly the height of the string in the UITextView in the DescriptionPopupViewController. This way if the description is longer, it will automatically make the popover higher.
The following code is called when the user clicks the UITextView:
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
if textView == descriptionTextView {
let sb = UIStoryboard(name: "Main-alternative", bundle: nil)
let popoverController = sb.instantiateViewControllerWithIdentifier("descriptionControllerID") as! DescriptionPopupViewController
popoverController.modalPresentationStyle = UIModalPresentationStyle.Popover
popoverController.popoverPresentationController?.delegate = popoverController;
popoverController.popoverPresentationController?.sourceView = descriptionTextView
popoverController.popoverPresentationController?.sourceRect = descriptionTextView.frame
popoverController.descriptionText = currentObject?["description"] as! String
if let frameHeight = popoverController.textView?.frame.height {
popoverController.preferredContentSize = CGSizeMake(fixedWidth, frameHeight)
}
self.presentViewController(popoverController, animated: true, completion: nil)
}
return false
}
So the preferredContentSize should get the height of the enclosed UITextView in the DescriptionPopupViewController. However when I try to do something like this it won't work:
I think because the frameHeight is nil
When the UIViewController is created its view hierarchy may not (and so all subviews, properties will still be nil), for optimization reasons it may not be loaded. You need to the access controller's view to force it to load its view hierarchy. So you need to update you code like the following:
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
if textView == descriptionTextView {
let sb = UIStoryboard(name: "Main-alternative", bundle: nil)
let popoverController = sb.instantiateViewControllerWithIdentifier("descriptionControllerID") as! DescriptionPopupViewController
popoverController.modalPresentationStyle = UIModalPresentationStyle.Popover
popoverController.popoverPresentationController?.delegate = popoverController;
popoverController.popoverPresentationController?.sourceView = descriptionTextView
popoverController.popoverPresentationController?.sourceRect = descriptionTextView.frame
// forces to load its view hierarchy
var view = popoverController.view
popoverController.descriptionText = currentObject?["description"] as! String
if let frameHeight = popoverController.textView?.frame.height {
popoverController.preferredContentSize = CGSizeMake(fixedWidth, frameHeight)
}
self.presentViewController(popoverController, animated: true, completion: nil)
}
return false
}
I hope this help you.