UIImagePickerController back button/cancel button is not visible - ios

I show the phone's gallery with an UIImagePickerController, but there is no back/cancel button on it. How can I add one?
What I have (inside a UIViewController):
func openGallery() {
let picker = UIImagePickerController()
picker.allowsEditing = false
picker.sourceType = .photoLibrary
picker.mediaTypes =
UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
present(picker, animated: true, completion: nil)
}
When I run this, I get the gallery, however there is no cancel button at top where it usually is.

Implement UIImagePickerControllerDelegate , UINavigationControllerDelegate and create a variable to assign UIImagePickerController var imagePicker = UIImagePickerController()
and set imagePicker.delegate = self.
func openGallary()
{
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}

Related

Preselecting images with UIImagePickerController

I have a standard code to open image picker, to select multiple images with it:
private func openFilesAction() {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
let imagePicker = UIImagePickerController()
customizePicker(picker: imagePicker)
imagePicker.delegate = self
imagePicker.mediaTypes = ["public.movie"]
imagePicker.sourceType = .photoLibrary;
imagePicker.allowsEditing = false
imagePicker.videoExportPreset = AVAssetExportPresetPassthrough
imagePicker.videoQuality = .typeHigh
self.present(imagePicker, animated: true, completion: nil)
}
}
But, I would like to have an ability to open picker again, and add or remove pictures to current selection. So the next time I open a picker, previously chosen images to be preselected.
Is this possible with a default picker, or I will have to do it custom (using CollectionView)?
You are not able to use multiple selection and preselection using UIImagePickerController

How to have a choose image button with a preview of last taken image

I am building a camera app and would like to have the last taken photo show up as a button to choose a photo. How would I do that?
Right now I am using UIImagePickerController to choose the image, and UIButton with just text to bring up the controller.
#IBAction func choosePhotoBtnPressed(_ sender: Any) {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .photoLibrary
imagePicker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String]
imagePicker.delegate = self
present(imagePicker, animated: true, completion: nil)
}
I want it to look like the stock camera app.
https://i1.wp.com/9to5mac.com/wp-content/uploads/sites/6/2013/09/screen-shot-2013-09-20-at-9-56-50-am.png?resize=1600%2C1000&quality=82&strip=all

How to add few options to UIImagePickerController

There is way to add few options to imagePicker sourceType?
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
The options is specific to the Camera app and is not available through the API.
You should file an enhancement request at http://bugreport.apple.com.
imagePicker.showsCameraControls = true. // use this
imagePicker.modalPresentationStyle = .FullScreen
If you make your own custom than you can create custom view
imagePicker.cameraOverlayView = YourView

UITabBar dissapear when dismiss UIImagePickerController

In my screenshot below, the structure of my storyboard are UITabBarController -> UINavigationController -> UIViewController. In my UIViewController, I call .Camera using UIImagePickerController in my viewDidLoad. However, when users hit Cancel inside the camera, I dismiss the ViewController, and my tab bar dissapears!
This is my codes for dismiss:
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
EDIT: Added calling of UIImagePickerController
override func viewDidLoad()
{
super.viewDidLoad()
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion: nil)
}
try to present the imagePicker Controller 'OverCurrentContext'
imagePicker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
or set it in the Storyboard in your UIViewController, hope it can help you.

how to show viewcontroller: UIImagePickController and dismiss it (Swift)

i got this uiactionsheet which loads uipickerviewcontroller
its in a viewcontroller thats in a UISplitViewController
It's a UIsplitviewcontroller, this code is on a detailview, the detailview is called from masterview
how ever, when i try to load it "click it" it gives me a warning and doesnt go any further
func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
switch buttonIndex{
case 0:
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePicker.allowsEditing = true
imagePicker.delegate = self
NSLog("Vælg fra Biblioteket");
break;
case 1:
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.allowsEditing = true
imagePicker.delegate = self
NSLog("Vælg Kamera");
break;
default:
NSLog("Default");
break;
}
self.presentViewController(imagePicker, animated: true, completion: nil) // this is the problem
}
the warning is this : Warning: Attempt to present on which is already presenting (null)
how ever if i use this :
self.showDeatilViewController(imagePicker, true) it show up but then i can't dismiss it at all
here's how i thought it would be dismissed
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
If i run this code in viewDidLoad, it works
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePickerController.allowsEditing = true
self.presentViewController(imagePickerController, animated: true, completion: { imageP in
})
I figured out that if i write this :
self.presentedViewController?.presentViewController(imagePicker, animated: true, completion: nil)
it shows and closes ?!?!
I've got it working... someone brought to my attention that 8.0 IOS has a bug with opening the photolibery and such from apps..
so i put it in the main queue like this
dispatch_async(dispatch_get_main_queue()){
imagePicker.delegate = self
self.presentViewController(imagePicker, animated: true, completion: nil)
}
and now it works!
little delay but it works

Resources