2016-01-12 3 views
0

У меня есть PHAsset, и я хочу получить PHLivePhoto.Как преобразовать PHAsset в PHLivePhoto

PHAsset является активом PHLivePhoto.

Я знаю эту функцию.

/// Requests a Live Photo from the given resource URLs. The result handler will be called multiple times to deliver new PHLivePhoto instances with increasingly more content. If a placeholder image is provided, the result handler will first be invoked synchronously to deliver a live photo containing only the placeholder image. Subsequent invocations of the result handler will occur on the main queue. 
// The targetSize and contentMode parameters are used to resize the live photo content if needed. If targetSize is equal to CGRectZero, content will not be resized. 
// When using this method to provide content for a PHLivePhotoView, each live photo instance delivered via the result handler should be passed to -  [PHLivePhotoView setLivePhoto:]. 
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *__nullable)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void(^)(PHLivePhoto *__nullable livePhoto, NSDictionary *info))resultHandler; 

Но я не знаю, как использовать.

Как сделать ставку?

ответ

0

Вы можете использовать этот метод из PHImageManager

- (PHImageRequestID)requestLivePhotoForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHLivePhotoRequestOptions *)options resultHandler:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))resultHandler 

Внутри ResultHandler вы получаете PHLivePhoto готовы показать в PHLivePhotoView.

Пример:

[[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:self.contentView.frame.size contentMode:PHImageContentModeDefault options:nil resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) { self.contentView.livePhoto = livePhoto }]; 
0
[asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { 
PHLivePhoto *livePhoto = [contentEditingInput.livePhoto]; 
}]; 
Смежные вопросы