我是iOS和Objective-C的新手,但我正在尝试创建一个包含一个组件的应用程序,该组件从相机胶卷中获取所有图像并从中创建幻灯片。我相信第一步是从存储在相机胶卷中的所有图像创建一个数组。然后我可以从这个数组创建一个动画。目前,我有一个按钮,指定为“播放”,选中后应将此幻灯片显示为UIImageView。但是,我的代码现在不能正常工作。任何帮助或建议将不胜感激。到目前为止,这是我的代码:
- (IBAction)play:(id)sender {
NSMutableArray *allPhotos= [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result == nil) {
return;
}
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
[allPhotos addObject:image];
}];
} failureBlock: ^(NSError *error) {
NSLog(@"No groups");
}];
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
animationImageView.animationImages = allPhotos;
animationImageView.animationDuration = 0.5;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
}
答案 0 :(得分:0)
由于现在不推荐使用ALAssetsLibrary,而Photo Framework是新的。我在Objective C中创建了自己的函数来从Camera Roll获取所有照片并存储在NSArray中并显示在我的Collectionview中
NSArray *imageArray;
NSMutableArray *mutableArray;
-(void)getAllPhotosFromCamera
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = true;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
NSLog(@"%d",(int)result.count);
PHImageManager *manager = [PHImageManager defaultManager];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];
// assets contains PHAsset objects.
__block UIImage *ima;
for (PHAsset *asset in result) {
// Do something with the asset
[manager requestImageForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info) {
ima = image;
[images addObject:ima];
}];
}
imageArray = [images copy]; // You can direct use NSMutuable Array images
}