我們有以下看法:選擇在一個視圖中不同的圖像具有的UIImagePickerController
所有代碼都運行良好,但是當我終於選擇一張圖片,照片被放置只是一個ImageView的。它應該像這樣工作: 我們點擊UIImageView下面的每個按鈕,並將選定的圖片放在他的ImageView中。
我現在的問題是,所有按鈕都將照片放在第一個UIImageView中。
如何放置4張不同的照片?
class selectorDeFotosViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate {
//Outlets
@IBOutlet weak var fotoUno: UIImageView!
@IBOutlet weak var fotoDos: UIImageView!
@IBOutlet weak var fotoTres: UIImageView!
@IBOutlet weak var fotoCuatro: UIImageView!
override func viewDidLoad() {
}
//Actions
@IBAction func CamaraUno(sender: AnyObject) {
let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
presentViewController(alertPictureFrom, animated: true, completion: nil)
alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 350.0, y: 458.0, width: 1.0, height: 1.0)
alertPictureFrom.popoverPresentationController?.sourceView = self.view
alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .Camera
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .PhotoLibrary
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
}
@IBAction func camaraDos(sender: AnyObject) {
let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
presentViewController(alertPictureFrom, animated: true, completion: nil)
alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 350.0, y: 458.0, width: 1.0, height: 1.0)
alertPictureFrom.popoverPresentationController?.sourceView = self.view
alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .Camera
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .PhotoLibrary
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
}
@IBAction func camaraTres(sender: AnyObject) {
let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
presentViewController(alertPictureFrom, animated: true, completion: nil)
alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 350.0, y: 458.0, width: 1.0, height: 1.0)
alertPictureFrom.popoverPresentationController?.sourceView = self.view
alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .Camera
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .PhotoLibrary
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
}
@IBAction func camaraCuatro(sender: AnyObject) {
let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
presentViewController(alertPictureFrom, animated: true, completion: nil)
alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 350.0, y: 458.0, width: 1.0, height: 1.0)
alertPictureFrom.popoverPresentationController?.sourceView = self.view
alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .Camera
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in
let picker = UIImagePickerController()
picker.sourceType = .PhotoLibrary
picker.delegate = self
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}))
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
fotoUno.image = image
picker.dismissViewControllerAnimated(true, completion: nil)
}
什麼是fotoUno?它是一個圖像視圖還是4個圖像視圖的屬性? –
fotoUno是左上方的插座UIImageView Mr.T – FactorJose
\你在問如何在相機選擇器上選擇多個圖像? –