IOS 相簿選擇器視訊的圖片選擇器 之下拉選擇相簿實現
阿新 • • 發佈:2019-02-10
引用塊內容
調研
目標:簡潔輕量效能優越
頂部就是自定義一個View裡面倆子View新增到titleView就行了。
下拉就是簡單的tabview。
開始擼(讓我們一起搖擺)
步驟:
1.頂部的標題和倒三角圖示
自定義一個View搞定
view裡面有UILabel和UIButton
值得記錄的是利用forState簡單的做到上下三角小圖示的切換
[titleArrow setImage:[UIImage imageNamed:@"dmcPicker.bundle/down_arrow.png"] forState:UIControlStateNormal];
[titleArrow set Image:[UIImage imageNamed:@"dmcPicker.bundle/up_arrow.png"] forState:UIControlStateSelected];
titleArrow.selected=YES;//切換圖片
2.獲取相簿的資料
本來的思路是用NSMutableDictionary來做Key存相簿的名字值就是相應相片陣列
但NSMutableDictionary的key 是無須的,所以不能做到取出順序所以放棄。
最終決定用量array,一個存相簿名,一個存相對相片
//獲取相簿
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeAlbumRegular options:nil ];
PHFetchResult *syncedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
PHFetchResult *userCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil ];
3.點擊出現相簿列表
思路是自定義一個view ,裡面包含一個UITableView
點標題就設定frame在navbar的下面。
沒遇到什麼搞的地方,IOS 11時候tableView 有個頭尾留白。如何去掉
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.00001;
}
4.最終大思路
進入介面就去getAlassetData 拿到資料後馬上呼叫,index 設定0
-(void)show:(NSInteger *)index{
fetchResult = dataSource[(int)index];
[self setTitleView:albumsTitlelist[(int)index]];
[_collectionView reloadData];
[self hiddenAlbumlistView];
[_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
nowSelectAlbum=index;
}
後面點了相簿列表的index後也是呼叫上面方法。
小坑筆記
bundle添加了圖片不顯示,去build phases 裡面找到bundle 然後show in finder看看
在一個預覽介面播放視訊呼叫了系統的播放器,覆蓋了預覽介面,返回時prearray被釋放了,從agin改為tetain