Swift3 在收藏视图xcode 8 swift 3.0.1中从库和相机的拼贴中显示多幅图像

Swift3 在收藏视图xcode 8 swift 3.0.1中从库和相机的拼贴中显示多幅图像,swift3,xcode8,Swift3,Xcode8,我正在研究swift 3.0.1和xcode 8.2.1, 我想从gallery中选择多个图像并在collectionView的不同拼贴中显示,当我从gallery中选择图像并按“完成”按钮时,collection view没有显示任何内容,但当我按“移动屏幕”时,屏幕上显示的图像。告诉我代码中有什么错误,以及如何获取任务。我导入这些框架照片、BSImagePicker、BSGridCollectionViewLayout。这是我的密码 @IBOutlet weak var collec

我正在研究swift 3.0.1和xcode 8.2.1, 我想从gallery中选择多个图像并在collectionView的不同拼贴中显示,当我从gallery中选择图像并按“完成”按钮时,collection view没有显示任何内容,但当我按“移动屏幕”时,屏幕上显示的图像。告诉我代码中有什么错误,以及如何获取任务。我导入这些框架照片、BSImagePicker、BSGridCollectionViewLayout。这是我的密码

    @IBOutlet weak var collection: UICollectionView!

    var imagePicker = UIImagePickerController()
    var imageArray = [UIImage]()


override func viewDidLoad() {

    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    imagePicker.delegate = self
    collection.delegate = self
    collection.dataSource = self

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func Camera(_ sender: Any) {
    if UIImagePickerController.isSourceTypeAvailable(.camera){
    imagePicker.sourceType = .camera
    imagePicker.allowsEditing = false
    imagePicker.cameraCaptureMode = .photo
    imagePicker.cameraFlashMode = .auto
    imagePicker.modalPresentationStyle = .fullScreen
    self.present(imagePicker, animated: true, completion: nil)

    }

else{

    let alert = UIAlertController(title: "No Camera", message: "Your Device has No Camera", preferredStyle: .alert)
    let action = UIAlertAction(title: "OK", style: .destructive, handler: nil)
    alert.addAction(action)
    self.present(alert, animated: true, completion: nil)
    }


    }


@IBAction func Library(_ sender: Any) {

    let vc = BSImagePickerViewController()
    vc.maxNumberOfSelections = 4
    //vc.takePhotoIcon = UIImage(named: "Tick")

    vc.albumButton.tintColor = UIColor.blue
    vc.cancelButton.tintColor = UIColor.blue
    vc.doneButton.tintColor = UIColor.blue
    vc.selectionCharacter = "✓"
    vc.selectionFillColor = UIColor.green
    vc.selectionStrokeColor = UIColor.clear
    vc.selectionShadowColor = UIColor.black
    vc.selectionTextAttributes[NSForegroundColorAttributeName] = UIColor.lightGray
    vc.cellsPerRow = {( verticalSize: UIUserInterfaceSizeClass, horizontalSize: UIUserInterfaceSizeClass) -> Int in

        switch (verticalSize, horizontalSize){

        case(.compact , .regular):
            return 3

        case (.compact, .compact): // iPhone5-6 landscape
            return 3
        case (.regular, .regular): // iPad portrait/landscape
            return 3
        default:
            return 3
        }

        }

    bs_presentImagePickerController(vc, animated: true, select: { (asset: PHAsset) -> Void in

        print("Selected: \(asset)")
        let imageManager = PHImageManager.default()

        let requestOptions = PHImageRequestOptions()
        requestOptions.isSynchronous = true
        requestOptions.deliveryMode = .highQualityFormat


        imageManager.requestImage(for: asset, targetSize: CGSize(width: 132, height: 114)  ,contentMode: .aspectFill, options: requestOptions, resultHandler:
            {

                image, error in
                self.imageArray.append(image!)

        })

        self.collection.reloadData()
    },

        deselect: { (asset: PHAsset) -> Void in
        print("Deselected: \(asset)")

    },
        cancel: { (asset: [PHAsset]) -> Void in
            print("Cancel: \(asset)")
        },

        finish: { (asset: [PHAsset]) -> Void in
            print("Finish: \(asset)")
        }, completion: nil)
    }

func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return imageArray.count

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let Cell : CellClass = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CellClass

    Cell.imageView.image = self.imageArray[indexPath.row]

    return Cell

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

     if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage  {

        imageArray.append(pickedImage)

     }

else {
    print("Image not Picked")

    }

    dismiss(animated: true, completion: nil)

}


func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    self.imagePicker = UIImagePickerController()
    dismiss(animated: true, completion: nil)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let width = collectionView.frame.width / 3 - 1


    return CGSize(width: width, height: width)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0
}

func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
    let cell = collectionView.cellForItem(at: indexPath)
    cell?.backgroundColor = UIColor.red
}

func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
    let cell = collectionView.cellForItem(at: indexPath)
    cell?.backgroundColor  = UIColor.green
}

你的问题解决了吗?你的问题解决了吗?