0

私のFirstVCでは、UIImagePickerControllerを使用してカメラをロードし、写真を撮り、1つのimageView(依然としてFirstVC内)に表示​​し、その画像をprepareForSegueを介してそこに表示されるSecondVC。iOS複数のimageView出力を持つカメラ

私が助けが必要なのは、FirstVCの中に複数のimageViewを置くと、最初の画像を1枚目の画像ビューに、2枚目の画像を2枚目の画像ビュー、3枚の画像を3枚目の画像ビュー、4枚目の画像を4枚目のimageView 。その後、ユーザがそれ以上写真を撮ることができないと言う警告が現れ、ユーザはnextSceneButtonを押して、直前に取った4つの選択された画像を表示するSecondVCに移動させる。

私はいつもUIImagePickerControllerを使いましたが、私はAVFoundationについて知りました。このタスクにAVFoundationまたはUIImagePickerを使用する必要がありますか?ここで

はFirstVC内側に一つだけImageViewのと私のUIImagePickerControllerコードです:

import UIKit 

class FirstViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 

@IBOutlet weak var imageView: UIImageView! 
@IBOutlet weak var nextSceneButton: UIButton! 
//nextSceneButton is connected in StoryBoards and triggers the segue to the SecondVC 


let imagePicker = UIImagePickerController() 

var image: UIImage? 



    //MARK:- Custom Function 
func noCamera(){ 
     let alertVC = UIAlertController(title: "No Camera", message: "Sorry, this device has no camera", preferredStyle: .Alert) 
     let okAction = UIAlertAction(title: "OK", style:.Default, handler: nil) 
     alertVC.addAction(okAction) 
     presentViewController(alertVC, animated: true, completion: nil) 
    } 


override func viewDidLoad() { 
     super.viewDidLoad() 
     imagePicker.delegate = self  
    } 


    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    //MARK:- Buttons 

@IBAction func libraryButtonPressed(sender: UIButton) { 
     imagePicker.allowsEditing = false 
     imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary 
     presentViewController(imagePicker, animated: true, completion: nil) 
    } 


@IBAction func photoButtonPressed(sender: UIButton) { 

    if (UIImagePickerController.availableCaptureModesForCameraDevice(UIImagePickerControllerCameraDevice.Rear) != nil){ 
      imagePicker.allowsEditing = false 
      imagePicker.sourceType = UIImagePickerControllerSourceType.Camera 
      imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo 
      imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.Rear 
      presentViewController(imagePicker, animated: true, completion: nil) 
     }else{ 
       noCamera() 
    } 
    } 


    //MARK:- ImagePickerController Delegates 

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
      let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage 
      self.image = chosenImage 
      imageView.image = self.image 
      dismissViewControllerAnimated(true, completion: nil) 
    } 


func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
      picker.dismissViewControllerAnimated(true, completion: nil) 
    } 


    //MARK:- Segue 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if segue.identifier == “fromPhotoVcToSecondVC” { 
     let secondVC = segue.destinationViewController as! SecondViewController 
     secondVC.image = self.image 
     } 
    } 

}//end class 
+0

必要なものにAvFoundationを使用する必要はありません。 didFinishPickingMediaWithInfoのカウンタを増やして、これが呼び出されるたびにそれぞれのImageviewをロードしてください。 – stefos

答えて

1

あなたはカウントプロパティを追加して、配列内のあなたのイメージを保持することができます:

var count = 0 
var imageViews:[UIImageView] 

あなたが取るたびに写真とデリゲートは、それぞれの画像ビューをロードすると呼ばれます。

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
     let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage 
     self.imageViews[count].image = chosenImage 
     count +=1 
     dismissViewControllerAnimated(true, completion: nil) 
} 

その後、すべての写真が撮られた場合、ユーザーには:

@IBAction func photoButtonPressed(sender: UIButton) { 
     if count < imageViews.count { 
      //present UiimagePicker 
     } else { 
      // alert no more pictures allowed 
     } 
} 
+0

Thansks非常に:)! –

関連する問題