Aber wenn ich mir den Code anderer ansehe, sehe ich, dass einige Leute Folgendes verwenden:
Code: Select all
imagePickerController.mediaTypes = [kUTTypeImage as String]
Ich habe das in meinem Code unten nicht verwendet, aber alles funktioniert immer noch gut.
Ich wähle solche Bilder über einen UIAlertController aus:
Code: Select all
//Check if camera exist
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
let cameraAction = UIAlertAction(title: "Take a photo", style: .Default) { (action) in
self.imagePicker.sourceType = .Camera
self.imagePicked = 1
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
alertController.addAction(cameraAction)
}
//Check if photo lib exist
if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
let photosLibraryAction = UIAlertAction(title: "Pick image", style: .Default) { (action) in
self.imagePicker.sourceType = .PhotoLibrary
self.imagePicked = 1
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
alertController.addAction(photosLibraryAction)
}
Code: Select all
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
//Change aspect when not dummy image
self.bigImage.contentMode = .ScaleAspectFill
self.bigImage.clipsToBounds = true
self.bigImage.image = pickedImage
Mobile version