澳门正规赌博十大网站-澳门游戏网站
做最好的网站

澳门游戏网站:纯代码自定义collectionview,iOS之相

经过自定义相册来介绍photo library的利用,photolibrary

  因为本人在模拟美图秀秀的机能,在使用相册时候,UIImagePickerController本来便是二个UINavigationController的子类,所以并未有主意使用push,所以做了叁个自定义的非UINavigationController子类的相册。使用的api是ios8之上提供的photokit。

  风姿洒脱、获取相册的兼具相册集

  比如:个人珍藏,目前加多,相机胶卷等。

  1.使用 (PHFetchResult<PHAssetCollection *> *)fetchAssetCollectionsWithType:(PHAssetCollectionType)type subtype:(PHAssetCollectionSubtype)subtype options:(nullable PHFetchOptions *)options方法来获得相册集集结

PHFetchResult再次回到了结果

  2.使用 (PHFetchResult<PHAsset *> *)fetchAssetsInAssetCollection:(PHAssetCollection *)assetCollection options:(nullable PHFetchOptions *)options方法来收获相册集内的兼具照片能源

  

- (PHFetchResult *)fetchAssetsInAssetCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending
{
    PHFetchOptions *options = [[PHFetchOptions alloc] init];
    options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:ascending]];
    PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];

    return result;
}

- (NSArray <PHAsset *> *)getAssetsInAssetCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending
{
    NSMutableArray <PHAsset *> *mArr = [NSMutableArray array];
    PHFetchResult *result = [self fetchAssetsInAssetCollection:assetCollection ascending:ascending];
    [result enumerateObjectsUsingBlock:^(PHAsset *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.mediaType == PHAssetMediaTypeImage) {
            [mArr addObject:obj];
        }
    }];

    return mArr;
}

- (NSArray<PHAsset *> *)getAllAssetInPhotoAblumWithAscending:(BOOL)ascending
{
    NSMutableArray<PHAsset *> *assets = [NSMutableArray array];

    PHFetchOptions *option = [[PHFetchOptions alloc] init];

    option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:ascending]];

    PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:option];

    [result enumerateObjectsUsingBlock:^(PHAsset *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [assets addObject:obj];
    }];

    return assets;
}

- (NSArray <FWPhotoAlbums *> *)getPhotoAlbums
{
    NSMutableArray<FWPhotoAlbums *> *mArr = [NSMutableArray array];
    PHFetchResult *smartAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
    [smartAlbum enumerateObjectsUsingBlock:^(PHAssetCollection *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.assetCollectionSubtype != 202 && obj.assetCollectionSubtype < 212) {
            NSArray <PHAsset *> *assets = [self getAssetsInAssetCollection:obj ascending:NO];
            if ([assets count]) {
                FWPhotoAlbums *pa = [[FWPhotoAlbums alloc] init];
                pa.albumName = [self TitleOfAlbumForChinse:obj.localizedTitle];
                pa.albumImageCount = [assets count];
                pa.firstImageAsset = assets.firstObject;
                pa.assetCollection = obj;
                [mArr addObject:pa];
            }
        }
    }];

    PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil];
    [userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection * _Nonnull collection, NSUInteger idx, BOOL * _Nonnull stop) {
        NSArray<PHAsset *> *assets = [self getAssetsInAssetCollection:collection ascending:YES];
        if (assets.count > 0) {
            FWPhotoAlbums *pa = [[FWPhotoAlbums alloc] init];
            pa.albumName = collection.localizedTitle;
            pa.albumImageCount = [assets count];
            pa.firstImageAsset = assets.firstObject;
            pa.assetCollection = collection;
            [mArr addObject:pa];
        }
    }];

    return mArr;
}

出于系统重回的相册集名称叫土耳其(Turkey卡塔尔国语,大家需求转移为粤语

- (NSString *)TitleOfAlbumForChinse:(NSString *)title
{
    if ([title isEqualToString:@"Slo-mo"]) {
        return @"慢动作";
    } else if ([title isEqualToString:@"Recently Added"]) {
        return @"最近添加";
    } else if ([title isEqualToString:@"Favorites"]) {
        return @"个人收藏";
    } else if ([title isEqualToString:@"Recently Deleted"]) {
        return @"最近删除";
    } else if ([title isEqualToString:@"Videos"]) {
        return @"视频";
    } else if ([title isEqualToString:@"All Photos"]) {
        return @"所有照片";
    } else if ([title isEqualToString:@"Selfies"]) {
        return @"自拍";
    } else if ([title isEqualToString:@"Screenshots"]) {
        return @"屏幕快照";
    } else if ([title isEqualToString:@"Camera Roll"]) {
        return @"相机胶卷";
    }
    return nil;
}

 

二、获取照片

- (void)requestImageForAsset:(PHAsset *)asset size:(CGSize)size resizeMode:(PHImageRequestOptionsResizeMode)resizeMode completion:(void (^)(UIImage *, NSDictionary *))completion
{
    static PHImageRequestID requestID = -1;
    CGFloat scale = [UIScreen mainScreen].scale;
    CGFloat width = MIN(WIDTH, 800);
    if (requestID >= 1 && size.width/width==scale) {
        [[PHCachingImageManager defaultManager] cancelImageRequest:requestID];
    }

    PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
    option.resizeMode = resizeMode;
    option.networkAccessAllowed = YES;

    requestID = [[PHCachingImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage * _Nullable image, NSDictionary * _Nullable info) {
        BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey];
        if (downloadFinined && completion) {
            completion(image, info);
        }
    }];
}

 

 

 三、拍照

  [_mCamera capturePhotoAsJPEGProcessedUpToFilter:_mFilter withCompletionHandler:^(NSData *processedJPEG, NSError *error){
        [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:processedJPEG options:nil];
        } completionHandler:^(BOOL success, NSError * _Nullable error) {

        }];
    }];

 

 

效果

澳门游戏网站 1       澳门游戏网站 2

 

代码

1.模型类,存储相册集名称,相片数,第一张相片以致该相册集满含的装有照片集结

澳门游戏网站 3#import <Foundation/Foundation.h> #import <photos/photos.h> @interface FWPhotoAlbums : NSObject @property (nonatomic, copy) NSString *albumName; //相册名字 @property (nonatomic, assign) NSUInteger albumImageCount; //该相册内相片数量 @property (nonatomic, strong) PHAsset *firstImageAsset; //相册第一张图片缩略图 @property (nonatomic, strong) PHAssetCollection *assetCollection; //相册集,通过该属性获取该相册集下全体照片 @end FWPhotoAlbums.h 澳门游戏网站 4#import "FWPhotoAlbums.h" @implementation FWPhotoAlbums @end FWPhotoAlbums.m

 

2.相片管理类,担负获取财富聚合,伏乞照片

澳门游戏网站 5#import <Foundation/Foundation.h> #import "FWPhotoAlbums.h" @interface FWPhotoManager : NSObject (instancetype)sharedManager; - (NSArray <FWPhotoAlbums *> *)getPhotoAlbums; - (NSArray<PHAsset *> *)getAllAssetInPhotoAblumWithAscending:(BOOL)ascending; - (NSArray<PHAsset *> *)getAssetsInAssetCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending; - (void)requestImageForAsset:(PHAsset *)asset size:(CGSize)size resizeMode:(PHImageRequestOptionsResizeMode)resizeMode completion:(void (^)(UIImage *image, NSDictionary *info))completion; - (void)requestImageForAsset:(PHAsset *)asset scale:(CGFloat)scale resizeMode:(PHImageRequestOptionsResizeMode)resizeMode completion:(void (^)(UIImage *image))completion; - (void)getPhotosBytesWithArray:(NSArray *)photos completion:(void (^)(NSString *photosBytes))completion; - (BOOL)judgeAssetisInLocalAblum:(PHAsset *)asset ; @end FWPhotoManager.h 澳门游戏网站 6#import "FWPhotoManager.h" @implementation FWPhotoManager (instancetype)sharedManager { static FWPhotoManager *manager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ manager = [[super allocWithZone:NULL] init]; }); return manager; } (instancetype)allocWithZone:(struct _NSZone *)zone { return [self sharedManager]; } - (PHFetchResult *)fetchAssetsInAssetCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending { PHFetchOptions *options = [[PHFetchOptions alloc] init]; options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:ascending]]; PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options]; return result; } - (NSArray <PHAsset *> *)getAssetsInAssetCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending { NSMutableArray <PHAsset *> *mArr = [NSMutableArray array]; PHFetchResult *result = [澳门游戏网站:纯代码自定义collectionview,iOS之相册新框架。self fetchAssetsInAssetCollection:assetCollection ascending:ascending]; [result enumerateObjectsUsingBlock:^(PHAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.mediaType == PHAssetMediaTypeImage) { [mArr addObject:obj]; } }]; return mArr; } - (NSArray<PHAsset *> *)getAllAssetInPhotoAblumWithAscending:(BOOL)ascending { NSMutableArray<PHAsset *> *assets = [NSMutableArray array]; PHFetchOptions *option = [[PHFetchOptions alloc] init]; option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:ascending]]; PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:option]; [result enumerateObjectsUsingBlock:^(PHAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [assets addObject:obj]; }]; return assets; } - (NSArray <FWPhotoAlbums *> *)getPhotoAlbums { NSMutableArray<FWPhotoAlbums *澳门游戏网站:纯代码自定义collectionview,iOS之相册新框架。> *mArr = [NSMutableArray array]; PHFetchResult *smartAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; [smartAlbum enumerateObjectsUsingBlock:^(PHAssetCollection * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.assetCollectionSubtype != 202 && obj.assetCollectionSubtype < 212) { NSArray <PHAsset *> *assets = [澳门游戏网站:纯代码自定义collectionview,iOS之相册新框架。self getAssetsInAssetCollection:obj ascending:NO]; if ([assets count]) { FWPhotoAlbums *pa = [[FWPhotoAlbums alloc] init]; pa.albumName = [self TitleOfAlbumForChinse:obj.localizedTitle]; pa.albumImageCount = [assets count]; pa.firstImageAsset = assets.firstObject; pa.assetCollection = obj; [mArr addObject:pa]; } } }]; PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil]; [userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection * _Nonnull collection, NSUInteger idx, BOOL * _Nonnull stop) { NSArray<PHAsset *> *assets = [self getAssetsInAssetCollection:collection ascending:YES]; if (assets.count > 0) { FWPhotoAlbums *pa = [[FWPhotoAlbums alloc] init]; pa.albumName = collection.localizedTitle; pa.albumImageCount = [assets count]; pa.firstImageAsset = assets.firstObject; pa.assetCollection = collection; [mArr addObject:pa]; } }]; return mArr; } - (NSString *)TitleOfAlbumForChinse:(NSString *)title { if ([title isEqualToString:@"Slo-mo"]) { return @"慢动作"; } else if ([title isEqualToString:@"Recently Added"]) { return @"近期增加"; } else if ([title isEqualToString:@"Favorites"]) { return @"个人珍藏"; } else if ([title isEqualToString:@"Recently Deleted"]) { return @"近年来剔除"; } else if ([title isEqualToString:@"Videos"]) { return @"视频"; } else if ([title isEqualToString:@"All Photos"]) { return @"全体照片"; } else if ([title isEqualToString:@"Selfies"]) { return @"自拍"; } else if ([title isEqualToString:@"Screenshots"]) { return @"荧屏快速照相"; } else if ([title isEqualToString:@"Camera Roll"]) { return @"相机胶卷"; } return nil; } - (void)requestImageForAsset:(PHAsset *)asset size:(CGSize)size resizeMode:(PHImageRequestOptionsResizeMode)resizeMode completion:(void (^)(UIImage *, NSDictionary *))completion { static PHImageRequestID requestID = -1; CGFloat scale = [UIScreen mainScreen].scale; CGFloat width = MIN(WIDTH, 800); if (requestID >= 1 && size.width/width==scale) { [[PHCachingImageManager defaultManager] cancelImageRequest:requestID]; } PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init]; option.resizeMode = resizeMode; option.networkAccessAllowed = YES; requestID = [[PHCachingImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage * _Nullable image, NSDictionary * _Nullable info) { BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]; if (downloadFinined && completion) { completion(image, info); } }]; } - (void)requestImageForAsset:(PHAsset *)asset scale:(CGFloat)scale resizeMode:(PHImageRequestOptionsResizeMode)resizeMode completion:(void (^)(UIImage *image))completion { PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init]; option.resizeMode = resizeMode;//调整照片尺寸 option.networkAccessAllowed = YES; [[PHCachingImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey] && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue]; if (downloadFinined && completion) { CGFloat sca = imageData.length/(CGFloat)UIImageJPEGRepresentation([UIImage imageWithData:imageData], 1).length; NSData *data = UIImageJPEGRepresentation([UIImage imageWithData:imageData], scale==1?sca:sca/2); completion([UIImage imageWithData:data]); } }]; } - (BOOL)judgeAssetisInLocalAblum:(PHAsset *)asset { PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init]; option.networkAccessAllowed = NO; option.synchronous = YES; __block BOOL isInLocalAblum = YES; [[PHCachingImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { isInLocalAblum = imageData ? YES : NO; }]; return isInLocalAblum; } @end FWPhotoManager.m

 

3.展现相册FWPhotoAlbumTableViewController

澳门游戏网站 7

澳门游戏网站 8#import <UIKit/UIKit.h> #import <Photos/Photos.h> @interface FWPhotoAlbumTableViewController : UITableViewController //最公投项数 @property (nonatomic, assign) NSInteger maxSelectCount; //是或不是选用了原图 @property (nonatomic, assign) BOOL isCanSelectMorePhotos; //当前已经选拔的图片 //@property (nonatomic, strong) NSMutableArray<ZLSelectPhotoModel *> *arraySelectPhotos; //选则达成后回调 //@property (nonatomic, copy) void (^DoneBlock)(NSArray<ZLSelectPhotoModel *> *selPhotoModels, BOOL isSelectOriginalPhoto); //废除选拔后回调 @property (nonatomic, copy) void (^CancelBlock)(); @end FWPhotoAlbumTableViewController.h 澳门游戏网站 9#import "FWPhotoAlbumTableViewController.h" #import "FWPhotoManager.h" #import "UIButton TextAndImageHorizontalDisplay.h" #import "FWPhotoCollectionViewController.h" #import "FWPhotosLayout.h" @interface FWPhotoAlbumTableViewController () { NSMutableArray<FWPhotoAlbums *> *mArr; } @end @implementation FWPhotoAlbumTableViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.title = @"相册"; mArr= [[[FWPhotoManager sharedManager] getPhotoAlbums] mutableCopy]; [self initNavgationBar]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } - (void)initNavgationBar { UIButton *rightBar = [UIButton buttonWithType:UIButtonTypeSystem]; rightBar.frame = CGRectMake(0, 0, 68, 32); [rightBar setImage:[UIImage imageNamed:@"Camera"] withTitle:@"相机" forState:UIControlStateNormal]; [rightBar addTarget:self action:@selector(cameraClicked) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBar]; } - (void)cameraClicked { } #pragma mark

  • Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [mArr count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; FWPhotoAlbums *album = mArr[indexPath.row]; cell.textLabel.text =album.albumName; cell.detailTextLabel.text = [NSString stringWithFormat:@"%d张",album.albumImageCount]; cell.detailTextLabel.textColor = [UIColor grayColor]; __block UIImage *img = nil; [[FWPhotoManager sharedManager] requestImageForAsset:album.firstImageAsset size:CGSizeMake(60 * 3, 60 * 3) resizeMode:PHImageRequestOptionsResizeModeExact completion:^(UIImage *image, NSDictionary *info) { img = image; }]; cell.imageView.image = img; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; cell.imageView.clipsToBounds = YES; return cell; } - (BOOL)prefersStatusBarHidden { return YES; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { FWPhotoAlbums *model = [mArr objectAtIndex:indexPath.row]; FWPhotosLayout *layout = [[FWPhotosLayout alloc] init]; layout.minimumInteritemSpacing = 1.5; layout.minimumLineSpacing = 5.0; FWPhotoCollectionViewController *vc = [[FWPhotoCollectionViewController alloc] initWithCollectionViewLayout:layout model:model]; [self.navigationController pushViewController:vc animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end FWPhotoAlbumTableViewController.m

 

4.显得相册集内全数照片FWPhotoCollectionViewController

澳门游戏网站 10#import <UIKit/UIKit.h> #import <Photos/Photos.h> #import "FWPhotoAlbums.h" @interface FWPhotoCollectionViewController : UICollectionViewController @property (nonatomic, strong) FWPhotoAlbums *model; - (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout model:(FWPhotoAlbums *)model; @end FWPhotoCollectionViewController.h

 

澳门游戏网站 11// // FWPhotoCollectionViewController.m // FWLifeApp // // Created by Forrest Woo on 16/9/23. // Copyright © 2016年 ForrstWoo. All rights reserved. // #import "FWPhotoCollectionViewController.h" #import "FWPhotoCell.h" #import "FWPhotoManager.h" #import "FWPhotosLayout.h" #import "FWDisplayBigImageViewController.h" @interface FWPhotoCollectionViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource> { NSArray<PHAsset *> *_dataSouce; } @property (nonatomic, strong) PHAssetCollection *assetCollection; @end @implementation FWPhotoCollectionViewController static NSString * const reuseIdentifier = @"Cell"; - (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout model:(FWPhotoAlbums *)model { if (self = [super initWithCollectionViewLayout:layout]) { self.model = model; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = NO; // self.navigationController.navigationBarHidden = YES; // Register cell classes CGRect frame = self.collectionView.frame; frame.origin.y =44; self.collectionView.frame = frame; self.view.backgroundColor = [UIColor whiteColor]; [self initSource]; } //- (void)setModel:(FWPhotoAlbums *)model //{ // self.model = model; // // [self initSource]; //} - (BOOL)prefersStatusBarHidden { return YES; } - (void)initSource { [self.collectionView registerClass:[FWPhotoCell class] forCellWithReuseIdentifier:reuseIdentifier]; self.title = self.model.albumName; self.automaticallyAdjustsScrollViewInsets = NO; // Do any additional setup after loading the view. self.assetCollection = self.model.assetCollection; _dataSouce = [[FWPhotoManager sharedManager] getAssetsInAssetCollection:self.assetCollection ascending:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark <UICollectionViewDataSource> - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [_dataSouce count]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { FWPhotosLayout *lay = (FWPhotosLayout *)collectionViewLayout; return CGSizeMake([lay cellWidth],[lay cellWidth]); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FWPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; PHAsset *asset = _dataSouce[indexPath.row]; __block UIImage *bImage = nil; CGSize size = cell.frame.size; size.width *= 3; size.height *= 3; [[FWPhotoManager sharedManager] requestImageForAsset:asset size:size resizeMode:PHImageRequestOptionsResizeModeFast completion:^(UIImage *image, NSDictionary *info) { bImage = image; }]; [cell setImage:bImage]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { PHAsset *asset = _dataSouce[indexPath.row]; [[FWPhotoManager sharedManager] requestImageForAsset:asset size:PHImageManagerMaximumSize resizeMode:PHImageRequestOptionsResizeModeFast completion:^(UIImage *image, NSDictionary *info) { FWDisplayBigImageViewController *vc = [[FWDisplayBigImageViewController alloc] initWithImage:image]; [self.navigationController pushViewController:vc animated:YES]; }]; } #pragma mark <UICollectionViewDelegate> @end FWPhotoCollectionViewController.m

 

澳门游戏网站 12

5.布局类

澳门游戏网站 13#import <UIKit/UIKit.h> @interface FWPhotosLayout : UICollectionViewFlowLayout @property (nonatomic, assign,readonly)CGFloat cellWidth; @end FWPhotosLayout.h 澳门游戏网站 14#import "FWPhotosLayout.h" @interface FWPhotosLayout () @property NSInteger countOfRow; @end @implementation FWPhotosLayout - (void)prepareLayout { [super prepareLayout]; self.countOfRow = ceilf([self.collectionView numberOfItemsInSection:0] / 4.0); } - (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *attris = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; NSInteger currentRow = indexPath.item / 4; CGRect frame = CGRectMake( (indexPath.item % 4) * ([self cellWidth] 5),currentRow * ([self cellWidth] 65), [self cellWidth], [self cellWidth]); attris.frame = frame; attris.zIndex = 1; return attris; } - (CGFloat)cellWidth { return (WIDTH - 3 * 5) / 4; } - (CGSize)collectionViewContentSize { return CGSizeMake(WIDTH, self.countOfRow * ([self cellWidth] 5) 44); } @end FWPhotosLayout.m

 

 

代码下载 

library的采取,photolibrary 因为小编在模仿美图秀秀的职能,在行使相册时候,UIImagePickerController本来即是四个UINav...

在iOS8.0事后,苹果推出了管理相册的新框架,在熟练现在的相册框架的情况下,再来看看新框架刚从前容许有的不适应,然而稳步的询问之后,你便会发觉,新框架让我们管理相册的接纳性越来越多,那个道理独有大家对新框架丰硕了然才会有那般的感到到;音信爆炸的时代,手艺生意盎然,只有的时候刻学习的饱满手艺与时俱进;下边简介一下新框架的采用。

鉴于未有用过collectionview,也是刚起首纯代码布局,所以查了重重材质和问了部分有情侣,总算消除难点

大器晚成、决断是或不是对相册及相机有使用权,作者在头里的博客有关联,在此边就只贴出链接:决断相册相机的行使权力

在vc里用到了别的的有的分拣,如有供给款待追问,互相学习。款待大神指导

二、多少个常用的类

群号:310800319

1、PHPhotoLibrary,相册的监听者,看名就会猜到其意义,能监听相册的调换,简单的说,当大家将照片存入本地相册的时候,那些类便会表明其效劳,是七个单例。

群号:246807516

始建监听者:[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];

步骤:

移除监听者:[[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self];

  1.自定义collectionviewCell类

相册变化的回调,即大家的多少更新改换在此个艺术中。

  2.模型类  

// This callback is invoked on an arbitrary serial queue. If you need this to be handled on a specific queue, you should redispatch appropriately 

  3. 在三个UIViewController里增多四个collectionView

 - (void)photoLibraryDidChange:(PHChange *)changeInstance; 

第一步:自定义cell

 2、PHFetchResult,相册管理类,通过那个那类大家能获取到系统相册及客商自定义相册。获取系统相册:

在cell的.h 里:

本文由澳门正规赌博十大网站发布于澳门游戏网站,转载请注明出处:澳门游戏网站:纯代码自定义collectionview,iOS之相