Ios 在CollectionView中将手机图库中的图像显示到手机中
单击单元格,我可以打开图库,我需要保存按下的图像并将其显示在单元格中,是否有帮助?您需要使用“资产库”框架从设备获取图像 您可以通过以下链接找到解决方案- 在iOS 9.0中不推荐使用AssetLibrary 所以使用了新的“照片”框架 下面是使用新框架的swift代码Ios 在CollectionView中将手机图库中的图像显示到手机中,ios,swift,uiimagepickercontroller,collectionview,Ios,Swift,Uiimagepickercontroller,Collectionview,单击单元格,我可以打开图库,我需要保存按下的图像并将其显示在单元格中,是否有帮助?您需要使用“资产库”框架从设备获取图像 您可以通过以下链接找到解决方案- 在iOS 9.0中不推荐使用AssetLibrary 所以使用了新的“照片”框架 下面是使用新框架的swift代码 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { imag
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: true, completion: nil)
}
// func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
// picker .dismissViewControllerAnimated(true, completion: nil)
// }
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
}
您需要使用以下代码包括标题-“导入照片”var pickedImage=UIImageView() PickeImage=info[UIImagePickerControllerOriginalImage]作为?UIImage CollectionView的in-cellForRowAtIndexPath方法
cell.imageview.image=pickedImageswift中是否有链接?因为这是目标c
func getAllImages() {
let imgManager : PHImageManager! = PHImageManager.defaultManager()
let photosArray : NSMutableArray! = NSMutableArray()
let requestOptions : PHImageRequestOptions! = PHImageRequestOptions()
let fetchOptions : PHFetchOptions! = PHFetchOptions()
requestOptions.synchronous = true
if let fetchResult: PHFetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions) {
if fetchResult.count > 0 {
for i in 0...fetchResult.count {
imgManager.requestImageForAsset(fetchResult.objectAtIndex(i) as! PHAsset, targetSize: view.frame.size, contentMode: PHImageContentMode.AspectFill, options: requestOptions, resultHandler: { (image, _) in
photosArray.addObject(image!)
});
}
}
}
}