{"id":175,"date":"2016-01-22T16:35:50","date_gmt":"2016-01-22T08:35:50","guid":{"rendered":"http:\/\/www.zhuyanbin.com\/?p=175"},"modified":"2016-12-09T22:13:19","modified_gmt":"2016-12-09T14:13:19","slug":"photokit-%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=175","title":{"rendered":"PhotoKit \u7b80\u4ecb"},"content":{"rendered":"<p>PhotoKit \u662f\u4e00\u5957\u6bd4 AssetsLibrary \u66f4\u5b8c\u6574\u4e5f\u66f4\u9ad8\u6548\u7684\u5e93\uff0c\u5bf9\u8d44\u6e90\u7684\u5904\u7406\u8ddf AssetsLibrary \u4e5f\u6709\u5f88\u5927\u7684\u4e0d\u540c\u3002<\/p>\n<p>\u9996\u5148\u7b80\u5355\u4ecb\u7ecd\u51e0\u4e2a\u6982\u5ff5\uff1a<\/p>\n<ul>\n<li><b>PHAsset<\/b>: \u4ee3\u8868\u7167\u7247\u5e93\u4e2d\u7684\u4e00\u4e2a\u8d44\u6e90\uff0c\u8ddf ALAsset \u7c7b\u4f3c\uff0c\u901a\u8fc7 PHAsset \u53ef\u4ee5\u83b7\u53d6\u548c\u4fdd\u5b58\u8d44\u6e90<\/li>\n<li><b>PHFetchOptions<\/b>: \u83b7\u53d6\u8d44\u6e90\u65f6\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u4f20 nil\uff0c\u5373\u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4\u503c<\/li>\n<li><b>PHFetchResult<\/b>: \u8868\u793a\u4e00\u7cfb\u5217\u7684\u8d44\u6e90\u96c6\u5408\uff0c\u4e5f\u53ef\u4ee5\u662f\u76f8\u518c\u7684\u96c6\u5408<\/li>\n<li><b>PHAssetCollection<\/b>: \u8868\u793a\u4e00\u4e2a\u76f8\u518c\u6216\u8005\u4e00\u4e2a\u65f6\u523b\uff0c\u6216\u8005\u662f\u4e00\u4e2a\u300c\u667a\u80fd\u76f8\u518c\uff08\u7cfb\u7edf\u63d0\u4f9b\u7684\u7279\u5b9a\u7684\u4e00\u7cfb\u5217\u76f8\u518c\uff0c\u4f8b\u5982\uff1a\u6700\u8fd1\u5220\u9664\uff0c\u89c6\u9891\u5217\u8868\uff0c\u6536\u85cf\u7b49\u7b49\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff09<\/li>\n<li><b>PHImageManager<\/b>: \u7528\u4e8e\u5904\u7406\u8d44\u6e90\u7684\u52a0\u8f7d\uff0c\u52a0\u8f7d\u56fe\u7247\u7684\u8fc7\u7a0b\u5e26\u6709\u7f13\u5b58\u5904\u7406\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f20\u5165\u4e00\u4e2a PHImageRequestOptions \u63a7\u5236\u8d44\u6e90\u7684\u8f93\u51fa\u5c3a\u5bf8\u7b49\u89c4\u683c<\/li>\n<li><b>PHImageRequestOptions<\/b>: \u5982\u4e0a\u9762\u6240\u8bf4\uff0c\u63a7\u5236\u52a0\u8f7d\u56fe\u7247\u65f6\u7684\u4e00\u7cfb\u5217\u53c2\u6570<\/li>\n<\/ul>\n<p>\u4e0b\u56fe\u4e2d UITableView \u7684\u7b2c\u4e8c\u4e2a section \u5c31\u662f PhotoKit \u6240\u5217\u51fa\u7684\u6240\u6709\u667a\u80fd\u76f8\u518c<\/p>\n<p><a href=\"http:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2016\/01\/1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-247\" src=\"http:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2016\/01\/1-1.png\" alt=\"\" width=\"616\" height=\"1093\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2016\/01\/1-1.png 751w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2016\/01\/1-1-169x300.png 169w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2016\/01\/1-1-577x1024.png 577w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/a><\/p>\n<p>\u518d\u5217\u51fa\u51e0\u4e2a\u4ee3\u7801\u7247\u6bb5\uff0c\u5c55\u793a\u5982\u4f55\u83b7\u53d6\u76f8\u518c\u4ee5\u53ca\u67d0\u4e2a\u76f8\u518c\u4e0b\u8d44\u6e90\u7684\u4ee3\u7801\uff1a<\/p>\n<div>\n<div id=\"highlighter_709466\" class=\"syntaxhighlighter objc\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<p>\/\/ \u5217\u51fa\u6240\u6709\u76f8\u518c\u667a\u80fd\u76f8\u518c<br \/>\nPHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];<\/p>\n<p>\/\/ \u5217\u51fa\u6240\u6709\u7528\u6237\u521b\u5efa\u7684\u76f8\u518c<br \/>\nPHFetchResult *topLevelUserCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];<\/p>\n<p>\/\/ \u83b7\u53d6\u6240\u6709\u8d44\u6e90\u7684\u96c6\u5408\uff0c\u5e76\u6309\u8d44\u6e90\u7684\u521b\u5efa\u65f6\u95f4\u6392\u5e8f<br \/>\nPHFetchOptions *options = [[PHFetchOptions alloc] init];<br \/>\noptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@&#8221;creationDate&#8221; ascending:YES]];<br \/>\nPHFetchResult *assetsFetchResults = [PHAsset fetchAssetsWithOptions:options];<\/p>\n<p>\/\/ \u5728\u8d44\u6e90\u7684\u96c6\u5408\u4e2d\u83b7\u53d6\u7b2c\u4e00\u4e2a\u96c6\u5408\uff0c\u5e76\u83b7\u53d6\u5176\u4e2d\u7684\u56fe\u7247<br \/>\nPHCachingImageManager *imageManager = [[PHCachingImageManager alloc] init];<br \/>\nPHAsset *asset = assetsFetchResults[0];<br \/>\n[imageManager requestImageForAsset:asset<br \/>\ntargetSize:SomeSize<br \/>\ncontentMode:PHImageContentModeAspectFill<br \/>\noptions:nil<br \/>\nresultHandler:^(UIImage *result, NSDictionary *info) {<\/p>\n<p>\/\/ \u5f97\u5230\u4e00\u5f20 UIImage\uff0c\u5c55\u793a\u5230\u754c\u9762\u4e0a<\/p>\n<p>}];<\/p>\n<\/div>\n<\/div>\n<p>\u7ed3\u5408\u4e0a\u9762\u51e0\u4e2a\u4ee3\u7801\u7247\u6bb5\u4e0a\u770b\uff0cPhotoKit \u76f8\u5bf9 AssetsLibrary \u4e3b\u8981\u6709\u4e09\u70b9\u91cd\u8981\u7684\u6539\u8fdb\uff1a<\/p>\n<ul>\n<li>\u4ece AssetsLibrary \u4e2d\u83b7\u53d6\u6570\u636e\uff0c\u65e0\u8bba\u662f\u76f8\u518c\uff0c\u8fd8\u662f\u8d44\u6e90\uff0c\u672c\u8d28\u4e0a\u90fd\u662f\u4f7f\u7528\u679a\u4e3e\u7684\u65b9\u5f0f\uff0c\u904d\u5386\u7167\u7247\u5e93\u53d6\u5f97\u76f8\u5e94\u7684\u6570\u636e\u3002\u800c PhotoKit \u5219\u662f\u901a\u8fc7\u4f20\u5165\u53c2\u6570\uff0c\u76f4\u63a5\u83b7\u53d6\u76f8\u5e94\u7684\u6570\u636e\uff0c\u56e0\u800c\u6548\u7387\u4f1a\u63d0\u9ad8\u4e0d\u5c11\u3002<\/li>\n<li>\u5728 AssetsLibrary \u4e2d\uff0c\u76f8\u518c\u548c\u8d44\u6e90\u662f\u5bf9\u5e94\u4e0d\u540c\u7684\u5bf9\u8c61\uff08ALAssetGroup \u548c ALAsset\uff09\uff0c\u56e0\u6b64\u83b7\u53d6\u76f8\u518c\u548c\u83b7\u53d6\u8d44\u6e90\u662f\u4e24\u4e2a\u5b8c\u5168\u6ca1\u6709\u5173\u8054\u7684\u63a5\u53e3\u3002\u800c PhotoKit \u4e2d\u5219\u6709 PHFetchResult \u8fd9\u4e2a\u53ef\u4ee5\u7edf\u4e00\u50a8\u5b58\u76f8\u518c\u6216\u8d44\u6e90\u7684\u5bf9\u8c61\uff0c\u56e0\u6b64\u5904\u7406\u76f8\u518c\u548c\u8d44\u6e90\u65f6\u4e5f\u4f1a\u6bd4\u8f83\u65b9\u4fbf\u3002<\/li>\n<li>PhotoKit \u8fd4\u56de\u8d44\u6e90\u7ed3\u679c\u65f6\uff0c\u540c\u65f6\u8fd4\u56de\u4e86\u8d44\u6e90\u7684\u5143\u6570\u636e\uff0c\u83b7\u53d6\u5143\u6570\u636e\u5728 AssetsLibrary \u4e2d\u662f\u5f88\u96be\u529e\u5230\u7684\u4e00\u4ef6\u4e8b\u3002\u540c\u65f6\u901a\u8fc7 PHAsset\uff0c\u5f00\u53d1\u8005\u8fd8\u80fd\u76f4\u63a5\u83b7\u53d6\u8d44\u6e90\u662f\u5426\u88ab\u6536\u85cf\uff08favorite\uff09\u548c\u9690\u85cf\uff08hidden\uff09\uff0c\u62cd\u6444\u56fe\u7247\u65f6\u662f\u5426\u5f00\u542f\u4e86 HDR \u6216\u5168\u666f\u6a21\u5f0f\uff0c\u751a\u81f3\u80fd\u901a\u8fc7\u4e00\u5f20\u8fde\u62cd\u56fe\u7247\u83b7\u53d6\u5230\u8fde\u62cd\u56fe\u7247\u4e2d\u7684\u5176\u4ed6\u56fe\u7247\u3002\u8fd9\u4e5f\u662f\u6587\u7ae0\u5f00\u5934\u8bf4\u7684\uff0c<b>PhotoKit \u80fd\u66f4\u597d\u5730\u4e0e\u8bbe\u5907\u7167\u7247\u5e93\u63a5\u5165\u7684\u4e00\u4e2a\u91cd\u8981\u56e0\u7d20\u3002<\/b><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>link:\u00a0<a href=\"http:\/\/kayosite.com\/ios-development-and-detail-of-photo-framework.html\" target=\"_blank\">http:\/\/kayosite.com\/ios-development-and-detail-of-photo-framework.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PhotoKit \u662f\u4e00\u5957\u6bd4 AssetsLibrary \u66f4\u5b8c\u6574\u4e5f\u66f4\u9ad8\u6548\u7684\u5e93\uff0c\u5bf9\u8d44\u6e90\u7684\u5904\u7406\u8ddf AssetsLib <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=175\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[30],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-ios","tag-ios"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":4,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}