Objective c 利用PHPhotoLibrary在UICollectionView中使用自定义单元格显示相机卷图像的最佳方法
大家好,我的应用程序有问题。。。在我的视图控制器hp中,有一个带有自定义单元格的CollectionView,该单元格应返回我的iphone应用程序图片的照相/摄像机滚动部分中的所有照片 现在我已经完成了在自定义单元格的ImageView中显示照片的所有步骤,到目前为止我没有问题。。。我的问题是,当我开始滚动浏览照片时,上传照片的速度非常慢,并且在应用程序崩溃后立即在日志中返回此错误 [GatekeeperXPC] 与assetsd的连接中断或assetsd死亡2017年2月25日20: [通用]创建图像 类型未知的格式错误 你能告诉我在我的收藏视图中展示图片的方式是否正确吗?我哪里出错了?因为我的应用程序崩溃了 谢谢你们能给我的任何帮助 这是我使用的代码Objective c 利用PHPhotoLibrary在UICollectionView中使用自定义单元格显示相机卷图像的最佳方法,objective-c,uicollectionview,uicollectionviewcell,ios10,phphotolibrary,Objective C,Uicollectionview,Uicollectionviewcell,Ios10,Phphotolibrary,大家好,我的应用程序有问题。。。在我的视图控制器hp中,有一个带有自定义单元格的CollectionView,该单元格应返回我的iphone应用程序图片的照相/摄像机滚动部分中的所有照片 现在我已经完成了在自定义单元格的ImageView中显示照片的所有步骤,到目前为止我没有问题。。。我的问题是,当我开始滚动浏览照片时,上传照片的速度非常慢,并且在应用程序崩溃后立即在日志中返回此错误 [GatekeeperXPC] 与assetsd的连接中断或assetsd死亡2017年2月25日20: [通用
- (void)viewDidLoad {
[super viewDidLoad];
self.nameTextField.delegate = self;
self.emailTextField.delegate = self;
self.passwordTextField.delegate = self;
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
_collectionView.backgroundColor = [UIColor clearColor];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_nameTextField becomeFirstResponder];
[self queryImage];
}
-(void)queryImage {
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
PHFetchResult *collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:fetchOptions];
if (collection.firstObject != nil ) {
_photoFound = YES;
_assetCollection = collection.firstObject;
} else {
}
_photoAsset = [PHAsset fetchAssetsInAssetCollection:_assetCollection options:nil];
[_collectionView reloadData];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(80,80);
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
NSUInteger count = 0;
if (_photoAsset != nil) {
count = [_photoAsset count];
}
return count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reuseIdentifier = @"imageCell";
UPCameraRollCollectionViewCell* cell = [cv dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
PHAsset *asset = [_photoAsset objectAtIndex:indexPath.item];
PHImageManager *imageManager = [PHImageManager defaultManager];
[imageManager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
[cell setThumbnailImage:result];
}];
return cell;
}
使用
苹果公司有一个能准确展示如何做你所追求的事情的系统。集合视图正是预期的用例。您能给我一个代码示例,以便更好地理解吗?我从来没有使用过PHPhotolibrary,这对我来说是个全新的笑话,不是吗,上帝说,“老兄,我已经给你派了两艘船和一架直升机……”看看这些文件!看看这个例子!