iOS中圖片與視頻一次性多選


一.使用系統的Assets Library Framework
這個是用來訪問Photos程序中的圖片和視頻的庫。其中幾個類解釋如下
  ALAsset
    ->包含一個圖片或視頻的各種信息

  ALAssetRepresentation
    ->得到ALAsset的各種信息

  ALAssetsFilter
    ->用來從一個ALAssetsGroup中檢索ALAssets

  ALAssetsGroup
    ->一組ALAsset,一個asset可以屬於多個這樣的組,可以添加一個asset到某個組中

  ALAssetsLibrary
    ->整個圖片庫中的內容,可以對圖片庫的獲取與編輯等

  網上有人說這種方法會要求授權地理位置信息,不過我沒有遇到...

看看官方的使用示例,枚舉的時候以nil結束哦,記得判斷處理下。

// The following example shows how you can get an asset to represent the first video in the Saved Photos Album.

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];

// For this example, we're only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {

// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
// Do something interesting with the AV asset.
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];

[library release];

 

二.網絡上的另一種方法-MHImagePickerMutilSelector
這個是通過設置UINavigationControllerDelegate的方法,當UIImagePickerController顯示在界面上的時候,判斷一下當前是圖集列表(相當於AlAssetsGroup的列表)還是圖片列表(相當於AlAsset的列表),如果是圖片列表就調整scrollview的大小,並在下面加上一個自己的滾動視圖用來顯示已經選擇的圖片。

這個方法的缺點是對已經選擇的圖片做點自定義的動作相對而言比較麻煩。

我稍微修改了下^_^(僅僅是稍微,讓它調用的時候簡單了點,對重復圖片什么的也沒有處理)

使用時只要UIVIewController實現了 MHImagePickerMutilSelector的協議,然后這樣調用就好了。

[MHImagePickerMutilSelector showInViewController:self];

 

這里下載。

 

參考:http://www.cocoachina.com/bbs/read.php?tid=112242


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM