Commit 541a0a7f authored by yuzheng.tz's avatar yuzheng.tz

优化性能:1. 初次进入时,提前渲染相册列表的tableView,避免初次进入相册页时的瞬间空白;2. 每次返回到相册页时,计算选中数量的任务放到后台,提升跳转流畅度

parent c4fb9265
......@@ -281,11 +281,9 @@
}];
}
if (!_pushPhotoPickerVc) {
TZAlbumPickerController *albumPickerVc = (TZAlbumPickerController *)self.visibleViewController;
if ([albumPickerVc isKindOfClass:[TZAlbumPickerController class]]) {
[albumPickerVc configTableView];
}
TZAlbumPickerController *albumPickerVc = (TZAlbumPickerController *)self.visibleViewController;
if ([albumPickerVc isKindOfClass:[TZAlbumPickerController class]]) {
[albumPickerVc configTableView];
}
}
......@@ -500,7 +498,7 @@
/*
// 兼容旧版本
if ([self.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[self.pickerDelegate imagePickerControllerDidCancel:self];
[self.pickerDelegate imagePickerControllerDidCancel:self];
}
*/
if ([self.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) {
......@@ -525,10 +523,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Photos"];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:imagePickerVc action:@selector(cancelButtonClick)];
[self configTableView];
// 1.6.10 采用微信的方式,只在相册列表页定义backBarButtonItem为返回,其余的顺系统的做法
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Back"] style:UIBarButtonItemStylePlain target:nil action:nil];
}
......@@ -537,53 +535,51 @@
[super viewWillAppear:animated];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[imagePickerVc hideProgressHUD];
if (_albumArr) {
for (TZAlbumModel *albumModel in _albumArr) {
albumModel.selectedModels = imagePickerVc.selectedModels;
}
[_tableView reloadData];
} else {
[self configTableView];
}
if (imagePickerVc.allowTakePicture) {
self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Photos"];
} else if (imagePickerVc.allowPickingVideo) {
self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Videos"];
}
[self configTableView];
}
- (void)configTableView {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[[TZImageManager manager] getAllAlbums:imagePickerVc.allowPickingVideo allowPickingImage:imagePickerVc.allowPickingImage completion:^(NSArray<TZAlbumModel *> *models) {
_albumArr = [NSMutableArray arrayWithArray:models];
for (TZAlbumModel *albumModel in _albumArr) {
albumModel.selectedModels = imagePickerVc.selectedModels;
}
if (!_tableView) {
CGFloat top = 0;
CGFloat tableViewHeight = 0;
if (self.navigationController.navigationBar.isTranslucent) {
top = 44;
if (iOS7Later) top += 20;
tableViewHeight = self.view.tz_height - top;
} else {
CGFloat navigationHeight = 44;
if (iOS7Later) navigationHeight += 20;
tableViewHeight = self.view.tz_height - navigationHeight;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[[TZImageManager manager] getAllAlbums:imagePickerVc.allowPickingVideo allowPickingImage:imagePickerVc.allowPickingImage completion:^(NSArray<TZAlbumModel *> *models) {
_albumArr = [NSMutableArray arrayWithArray:models];
for (TZAlbumModel *albumModel in _albumArr) {
albumModel.selectedModels = imagePickerVc.selectedModels;
}
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, tableViewHeight) style:UITableViewStylePlain];
_tableView.rowHeight = 70;
_tableView.tableFooterView = [[UIView alloc] init];
_tableView.dataSource = self;
_tableView.delegate = self;
[_tableView registerClass:[TZAlbumCell class] forCellReuseIdentifier:@"TZAlbumCell"];
[self.view addSubview:_tableView];
} else {
[_tableView reloadData];
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
if (!_tableView) {
CGFloat top = 0;
CGFloat tableViewHeight = 0;
if (self.navigationController.navigationBar.isTranslucent) {
top = 44;
if (iOS7Later) top += 20;
tableViewHeight = self.view.tz_height - top;
} else {
CGFloat navigationHeight = 44;
if (iOS7Later) navigationHeight += 20;
tableViewHeight = self.view.tz_height - navigationHeight;
}
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, tableViewHeight) style:UITableViewStylePlain];
_tableView.rowHeight = 70;
_tableView.tableFooterView = [[UIView alloc] init];
_tableView.dataSource = self;
_tableView.delegate = self;
[_tableView registerClass:[TZAlbumCell class] forCellReuseIdentifier:@"TZAlbumCell"];
[self.view addSubview:_tableView];
} else {
[_tableView reloadData];
}
});
}];
});
}
- (void)dealloc {
......@@ -610,10 +606,6 @@
photoPickerVc.columnNumber = self.columnNumber;
TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model;
__weak typeof(self) weakSelf = self;
[photoPickerVc setBackButtonClickHandle:^(TZAlbumModel *model) {
[weakSelf configTableView];
}];
[self.navigationController pushViewController:photoPickerVc animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
......
......@@ -15,8 +15,6 @@
@property (nonatomic, assign) NSInteger columnNumber;
@property (nonatomic, strong) TZAlbumModel *model;
@property (nonatomic, copy) void (^backButtonClickHandle)(TZAlbumModel *model);
@end
......
......@@ -71,39 +71,52 @@ static CGSize AssetGridThumbnailSize;
self.navigationItem.title = _model.name;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:tzImagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:tzImagePickerVc action:@selector(cancelButtonClick)];
_showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture);
if (!tzImagePickerVc.sortAscendingByModificationDate && _isFirstAppear && iOS8Later) {
[[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(TZAlbumModel *model) {
_model = model;
_models = [NSMutableArray arrayWithArray:_model.models];
[self initSubviews];
}];
} else {
if (_showTakePhotoBtn || !iOS8Later || _isFirstAppear) {
[[TZImageManager manager] getAssetsFromFetchResult:_model.result allowPickingVideo:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(NSArray<TZAssetModel *> *models) {
_models = [NSMutableArray arrayWithArray:models];
// [self resetCachedAssets];
}
- (void)fetchAssetModels {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_isFirstAppear) {
[tzImagePickerVc showProgressHUD];
}
dispatch_sync(dispatch_get_global_queue(0, 0), ^{
if (!tzImagePickerVc.sortAscendingByModificationDate && _isFirstAppear && iOS8Later) {
[[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(TZAlbumModel *model) {
_model = model;
_models = [NSMutableArray arrayWithArray:_model.models];
[self initSubviews];
}];
} else {
_models = [NSMutableArray arrayWithArray:_model.models];
[self initSubviews];
if (_showTakePhotoBtn || !iOS8Later || _isFirstAppear) {
[[TZImageManager manager] getAssetsFromFetchResult:_model.result allowPickingVideo:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(NSArray<TZAssetModel *> *models) {
_models = [NSMutableArray arrayWithArray:models];
[self initSubviews];
}];
} else {
_models = [NSMutableArray arrayWithArray:_model.models];
[self initSubviews];
}
}
}
// [self resetCachedAssets];
});
}
- (void)initSubviews {
[self checkSelectedModels];
[self configCollectionView];
[self configBottomToolBar];
dispatch_async(dispatch_get_main_queue(), ^{
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
[tzImagePickerVc hideProgressHUD];
[self checkSelectedModels];
[self configCollectionView];
[self configBottomToolBar];
[self scrollCollectionViewToBottom];
});
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
tzImagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
if (self.backButtonClickHandle) {
self.backButtonClickHandle(_model);
}
}
- (BOOL)prefersStatusBarHidden {
......@@ -151,7 +164,6 @@ static CGSize AssetGridThumbnailSize;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self scrollCollectionViewToBottom];
// Determine the size of the thumbnails to request from the PHCachingImageManager
CGFloat scale = 2.0;
if ([UIScreen mainScreen].bounds.size.width > 600) {
......@@ -159,6 +171,10 @@ static CGSize AssetGridThumbnailSize;
}
CGSize cellSize = ((UICollectionViewFlowLayout *)_collectionView.collectionViewLayout).itemSize;
AssetGridThumbnailSize = CGSizeMake(cellSize.width * scale, cellSize.height * scale);
if (!_models) {
[self fetchAssetModels];
}
}
- (void)viewDidAppear:(BOOL)animated {
......
......@@ -200,7 +200,7 @@
if (self.maxCountTF.text.integerValue <= 0) {
return;
}
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCountTF.text.integerValue columnNumber:self.columnNumberTF.text.integerValue delegate:self pushPhotoPickerVc:NO];
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCountTF.text.integerValue columnNumber:self.columnNumberTF.text.integerValue delegate:self pushPhotoPickerVc:YES];
#pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment