Ich muss eine Ansicht erstellen, die wie Seiten funktioniert, mit einem Popup, in dem ich wählen kann, ein Foto aus meiner Bibliothek auszuwählen oder ein neues zu erstellen.Include UIImagePickerController in einer Ansicht
Derzeit habe ich einen ViewController, als Popover vorhanden. Im ViewController habe ich ein ContainerView eingefügt und ich habe erklärt, dass seine Klasse UIImageViewController ist. Dies zeigt mir die Fotobibliothek, aber ich finde nicht, wie man etwas auswählt: My ViewController presented as Popover.
Wenn ich ein Foto wähle, passiert nichts. Ich habe versucht, einige Funktionen
(func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!))
in meinem ViewController zu setzen, aber es funktioniert nicht. Ich habe gelesen, dass UIImagePickerController Unterklassen nicht unterstützt, also wie Seiten dieses Zeug machen?
Hier ist meine Viewcontroller-Code:
import UIKit
class MenuAddResources: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var newMedia: Bool?
let imagePicker = UIImagePickerController()
@IBAction func takePhoto(sender: AnyObject) {
if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
//load the camera interface
let picker : UIImagePickerController = UIImagePickerController()
picker.sourceType = UIImagePickerControllerSourceType.Camera
picker.delegate = self
picker.allowsEditing = false
self.presentViewController(picker, animated: true, completion: nil)
self.newMedia = true
}
else{
//no camera available
let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("NO_CAMERA", comment: ""), preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Default, handler: {(alertAction)in
alert.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafePointer<Void>) {
if error != nil {
let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("IMAGE_SAVE_FAILED", comment: ""), preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Cancel, handler: nil)
alert.addAction(cancelAction)
self.presentViewController(alert, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.dismissViewControllerAnimated(true, completion: {() -> Void in
})
// Let's store the image
let now:Int = Int(NSDate().timeIntervalSince1970)
let imageData = UIImageJPEGRepresentation(image, 85)
//imageData?.writeToFile(documentsDirectory + "/\(now).jpg", atomically: true)
print(imageData)
/* will do stuff with the image */
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
bitte auch einen entsprechenden Code teilen – Shubhank
ich bearbeitet haben. Etwas sehr Seltsames ist, wenn ich die Zeile "let imagePicker = UIImagePickerController()" nicht setzen, wird der Picker nicht angezeigt ... –
_Wenn ich ein Foto wähle, passiert nichts. Ich habe versucht, einige Funktionen zu setzen. Du willst also sagen, dass UIImagePicker kommt, aber du kannst kein Foto von ihm auswählen? – Shubhank