Swift PHPicker cancel button changes color - ios

I am currently using the PHPicker from apple. Works great but whenever I switch to the album segment the cancel button changes colour to white, making it barely visible. When I switch back to all it stays white. Like so:
code to initialise the picker:
var config = PHPickerConfiguration(photoLibrary: .shared())
config.selectionLimit = 50
config.filter = .images
let vc = PHPickerViewController(configuration: config)
vc.delegate = self
present(vc, animated: true, completion: nil)
Any idea?

Related

UIDocumentPickerController does not occupy entire screen in IOS14

I am using following code to import files,
if #available(iOS 14, *) {
let supportedTypes: [UTType] = [UTType.text, UTType.data]
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
self.present(documentPicker, animated: true, completion: nil)
}
In the output we can see transparent view between "Recent/Browser" tab bar and document content view.
Here is the screenshot of the output:
image 1
image 2
If I change the presentation style to fullScreen, transparent view will become grey coloured view
documentPicker.modalPresentationStyle = .fullScreen
Here is the screenshot of the fullScreen output:
image 3
image 4
Does anyone know how to resolve this?
Check UITabBar.appearance().isTranslucent property.
I had the same problem when this property was false

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)
}

Swift ViewController Background getting black with alpha

I'm calling a ViewController as popover when the user presses a button. The View should have black background with alpha 0.5.
But the View is shown as that for a second, than the whole background turns black without alpha. Any idea why?
Thats my popover call:
let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .popover
self.present(popOver, animated: true, completion: nil)
I'm trying to set the background color in popovers viewDidLoad() function with following code:
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
For that set modalPresentationStyle to overCurrentContext instead of popover.
let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .overCurrentContext
self.present(popOver, animated: true)

Dismissing of UIImagePickerController dismisses presenting view controller also

I am working on a project that uses tabbar system. One of the item of tabbar is JobPostingViewController. I Embed it in UINavigationController. There is a UIButton called add new job in this view controller .I implemented pushviewcontroller to go CreateJobPostViewController. There I need to add UIImagePickerController to choose the image. When i tap done button or choose an image from library it dismisses to JobPostingViewController. But it should go to the CreateJobPostViewController.
Any one please help me. Thanks in advance.
You can see the issue here:
Code in JobPostingViewController
#IBAction func openCreateJob(sender: AnyObject) {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CreateJobPostViewController") as! CreateJobPostViewController
self.navigationController?.pushViewController(vc, animated: true)
}
Code in CreateJobPostViewController
#IBAction func addImages(sender: AnyObject) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
Fixed the issue by setting the image picker's modalPresentationStyle to "OverCurrentContext":
picker.modalPresentationStyle = .overCurrentContext
Adding Picker as subview
try to add the imagepicker as a subview to your CreateJobPostViewController insted of presenting it and then remove it from parent in the delegtes
#IBAction func openCreateJob(sender: AnyObject) {
var picker: UIImagePickerController = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = .PhotoLibrary
self.addChildViewController(picker)
picker.didMoveToParentViewController(self)
self.view!.addSubview(picker.view!)
}
and then
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.view!.removeFromSuperview()
picker.removeFromParentViewController()
}
For presenting
showing picker over currentcontext with options like edit cancel choose,
use picker.modalPresentationStyle = .overCurrentContext //before presenting
it
presentViewController(picker, animated: true, completion: nil)
You could use:
picker.modalPresentationStyle = .overCurrentContext
but depending on your screen layout, it may be better to use:
picker.modalPresentationStyle = .overFullScreen
otherwise your "cancel", "retake" and "use photo" buttons may not be visible.
I had this same problem, I solved it using the storyboard (Xcode v9.2)
1 - Go to the storyboard, where is your ViewController, select it
2 - Set Presentation as: Current Context
Note: If it does not work Current Context, select Over Current Context
I was trying to present the picker over an iOS 13 popover view controller. To stop the camera from dismissing my popover view controller I had to change the picker's modalPresentationStyle to popover. See below:
picker.modalPresentationStyle = .popover

Wrong popup transition when UIImagePickerController is being presented in a UIPopoverPresentationController on iPad

I was trying to present a UIImagePickerController with source type .PhotoLibrary on iPad. Following Apple's recommendation, it's presented in a popover by using UIPopoverPresentationController.
Here is the actual method for presenting the image picker:
func openImagePicker(with sourceType: UIImagePickerControllerSourceType, from button: UIButton) {
guard UIImagePickerController.isSourceTypeAvailable(sourceType) else {
return
}
guard let mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(sourceType) else {
return
}
let picker = UIImagePickerController()
picker.sourceType = sourceType
picker.mediaTypes = mediaTypes
picker.delegate = self
picker.modalPresentationStyle = .Popover
presentViewController(picker, animated: true, completion: nil)
if let popover = picker.popoverPresentationController {
popover.sourceView = button
popover.sourceRect = button.bounds
}
}
The issue I noticed, particularly on iPad in landscape mode, is that when I went into an album and tapped Back button to go back, the popup transition animation looks like the view is flying off the screen, which is totally weird.
It only happens on landscape. No issue on portrait mode.
I tried searching for similar issues but couldn't find any. Does anyone encounter the same problem, and how did you fix it?

Resources