How to add few options to UIImagePickerController - ios

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

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

UIImagePickerController back button/cancel button is not visible

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

Crop square photo with picker.allowsEditing = true in Swift

I'm currently coding a social app which permits to share pictures. The user has the possibility to share pictures from his/her library.
func selectImg() {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
picker.mediaTypes = ["public.image"]
picker.allowsEditing = true
present(picker, animated: true, completion: nil)
}
Then, the user has to crop the picture in order to having a square version of it. For that, I wrote picker.allowsEditing = true, but the problem is that the cropped zone is not seems to be improper, here is what is looks like:
As you can see with this square picture, the cropping zone is displaced and I really don't know why. I tried to check if users had the same problem, but no result.

UIImagePickerController slow on opening for the first time, except for when you double tap

I'm getting this really weird behaviour on iOS 9 with swift where I have a tableViewCell that opens an imagePicker when tapped on to take a picture of something, when you tap the cell for the first time it takes like 10 seconds to open the picker, but when you tap it twice it immediately opens...
The initialisation code for the picker is as follows
let certificateImagePicker = UIImagePickerController()
certificateImagePicker.delegate = self
certificateImagePicker.allowsEditing = false
certificateImagePicker.sourceType = .Camera
certificateImagePicker.modalPresentationStyle = .CurrentContext
The code for presenting the picker is presentViewController(certificateImagePicker, animated: false, completion: nil)
I do not now if it related but after opening the picker it show this error message
Snapshotting a view that has not been rendered results in an empty snapshot.
Ensure your view has been rendered at least once before snapshotting or
snapshot after screen updates.
I experienced a similar delay in presenting a UIImagePickerController on the first try. What helped a lot in my case was initialising it when also initializing the parent UIViewController, like so:
class ExampleViewController: UIViewController, UIImagePickerControllerDelegate {
let imagePicker = UIImagePickerController()
func presentImagePicker() {
imagePicker.delegate = self
imagePicker.allowsEditing = false
imagePicker.sourceType = .camera
imagePicker.modalPresentationStyle = .currentContext
self.present(imagePicker, animated: false, completion: nil)
}
}
This is only for debug builds, when you run an app connected to Xcode.
private var imagePickerController = UIImagePickerController()
...
#objc func addPhoto() {
imagePickerController.delegate = self
imagePickerController.sourceType = .savedPhotosAlbum
present(imagePickerController, animated: true)
}
...
When I have this implementation it was waiting when the first present was attempted then after changed my variable to lazy variable, then it worked like charm.
private lazy var imagePickerController = UIImagePickerController()

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