Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用NohanaImagePicker pod文件查看图像?_Ios_Swift3_Image Gallery_Collectionview_Photolibrary - Fatal编程技术网

Ios 如何使用NohanaImagePicker pod文件查看图像?

Ios 如何使用NohanaImagePicker pod文件查看图像?,ios,swift3,image-gallery,collectionview,photolibrary,Ios,Swift3,Image Gallery,Collectionview,Photolibrary,我正在使用swift 3并使用NohanaImagePickerpod文件选择多个图像,其工作正常。问题是,我希望在“集合”视图中查看所选图像,我将在此行中收到致命错误 cell.imageforCV.image = ViewController.imgArray[indexPath.row] 我在imgaray中使用了静态变化 这是我的密码 import UIKit import Photos import NohanaImagePicker class ViewCont

我正在使用swift 3并使用NohanaImagePickerpod文件选择多个图像,其工作正常。问题是,我希望在“集合”视图中查看所选图像,我将在此行中收到致命错误

        cell.imageforCV.image =  ViewController.imgArray[indexPath.row]
我在imgaray中使用了静态变化

这是我的密码

import UIKit
import Photos
import NohanaImagePicker

class ViewController: UIViewController , NohanaImagePickerControllerDelegate , UICollectionViewDelegate , UICollectionViewDataSource {

static var imgArray = [UIImage]()
static var imgCount = Int()
@IBOutlet weak var imageCollectionView: UICollectionView!
var images = [ PHAsset]()
@IBAction func gallery(_ sender: UIButton) {

 let picker = NohanaImagePickerController()
    picker.delegate = self
    present(picker, animated: true, completion: nil)
    picker.maximumNumberOfSelection  = 200
    print("\(picker)")


}
 func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
    print("Canceled")
    picker.dismiss(animated: true, completion: nil)
}

   func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset]) {
    print("Completed\n\tpickedAssets = \(pickedAssts)")
    picker.dismiss(animated: true, completion: nil)
    performSegue(withIdentifier: "back", sender: self)
    let numberOfImages = pickedAssts.count
    print("\(numberOfImages)")


    ViewController.imgCount = pickedAssts.count

    var phAssetArray : [PHAsset] = []

    for i in 0..<pickedAssts.count
    {
        ViewController.imgArray.append(self.getAssetThumbnail(asset: pickedAssts[i]));
    }
    let size = CGSize(width: 50, height: 50)
    let options = PHImageRequestOptions()

    let manager : PHCachingImageManager =  PHCachingImageManager()


    manager.startCachingImages(for: phAssetArray,
                                                  targetSize: size,
                                                  contentMode: .aspectFill,
                                                  options: options)

    imageCollectionView.reloadData()
              }


func getAssetThumbnail(asset: PHAsset) -> UIImage {
    var retimage = UIImage()
    print(retimage)
    let manager = PHImageManager.default()
    manager.requestImage(for: asset, targetSize: CGSize(width: 50.0, height: 50.0), contentMode: .aspectFit, options: nil, resultHandler: {(result, info)->Void in
        retimage = result!
    })
    print(retimage)
    return retimage
}

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


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! imageCell

    print(ViewController.imgArray.count)
    print(indexPath.row)
    print(ViewController.imgArray[indexPath.row])



    cell.imageforCV.image =  ViewController.imgArray[indexPath.row]

    return cell

}


   override func viewDidLoad() {
         super.viewDidLoad()

         imageCollectionView.reloadData()

         self.imageCollectionView!.dataSource = self
         self.imageCollectionView!.delegate = self


    let picker = NohanaImagePickerController()

    // Set the maximum number of selectable images

    // Set the cell size
    picker.numberOfColumnsInPortrait = 2
    picker.numberOfColumnsInLandscape = 3

    // Show Moment
    picker.shouldShowMoment = true

    // Show empty albums
    //        picker.shouldShowMoment = shouldShowEmptyAlbum = true

    // Hide toolbar
    picker.shouldShowEmptyAlbum = true

    // Disable to pick asset
    picker.canPickAsset = { (asset:Asset) -> Bool in
        return false
    }

    // Color
    ColorConfig.backgroundColor = UIColor.white
   }
导入UIKit
导入照片
导入图像选择器
类ViewController:UIViewController、NohanaImagePickerController、UICollectionViewDelegate、UICollectionViewDataSource{
静态变量imgaray=[UIImage]()
静态变量imgCount=Int()
@IBVAR imageCollectionView:UICollectionView!
变量图像=[PHAsset]()
@iAction func库(uu发件人:ui按钮){
让picker=NohanaImagePickerController()
picker.delegate=self
当前(选择器,动画:真,完成:无)
picker.maximumNumberOfSelection=200
打印(“\(选择器)”)
}
func nohanaImagePickerDidCancel(picker:NohanaImagePickerController){
打印(“已取消”)
picker.disclose(动画:true,完成:nil)
}
func nohanaImagePicker(uPicker:NohanaImagePickerController,DidFinishPickingPhotoKit已拾取资产:[PHAsset]){
打印(“已完成的\n\tpickedAssets=\(拾取的assts)”)
picker.disclose(动画:true,完成:nil)
性能检查(标识符为“back”,发送者为self)
让numberOfImages=pickedAssets.count
打印(“\(numberOfImages)”)
ViewController.imgCount=pickedAssts.count
var phAssetArray:[PHAsset]=[]
对于0..UIImage中的i{
var retimage=UIImage()
打印(重成像)
let manager=PHImageManager.default()
requestImage(for:asset,targetSize:CGSize(宽度:50.0,高度:50.0),contentMode:.aspectFit,选项:nil,resultHandler:{(结果,信息)->Void in
重成像=结果!
})
打印(重成像)
返回重映像
}
func collectionView(collectionView:UICollectionView,numberOfItemsInSection:Int)->Int{
返回ViewController.imgArray.count
}
func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->UICollectionViewCell{
让cell=imageCollectionView.dequeueReusableCell(使用ReuseIdentifier:“imageCell”,for:indexPath)作为!imageCell
打印(ViewController.imgaray.count)
打印(indexPath.row)
打印(ViewController.imgArray[indexPath.row])
cell.imageforCV.image=ViewController.imgArray[indexPath.row]
返回单元
}
重写func viewDidLoad(){
super.viewDidLoad()
imageCollectionView.reloadData()
self.imageCollectionView!.dataSource=self
self.imageCollectionView!.delegate=self
让picker=NohanaImagePickerController()
//设置可选择图像的最大数量
//设置单元格大小
picker.numberofcolumnsintrait=2
picker.NumberOfColumnSin横向=3
//表演时刻
picker.shouldShowMoment=真
//显示空相册
//picker.shouldShowMoment=shouldShowEmptyAlbum=true
//隐藏工具栏
picker.shouldShowEmptyAlbum=true
//禁用以拾取资产
picker.canPickAsset={(资产:资产)->Bool-in
返回错误
}
//颜色
ColorConfig.backgroundColor=UIColor.white
}
使用以下功能

    func getAssetThumbnail(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.version = .original
    option.isSynchronous = true
    manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in thumbnail = result! })
    return thumbnail
}
让我们以第一个资产为例

    let phAsset = pickedAssts.first