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

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

parent c4fb9265
......@@ -281,12 +281,10 @@
}];
}
if (!_pushPhotoPickerVc) {
TZAlbumPickerController *albumPickerVc = (TZAlbumPickerController *)self.visibleViewController;
if ([albumPickerVc isKindOfClass:[TZAlbumPickerController class]]) {
[albumPickerVc configTableView];
}
}
}
- (void)showAlertWithTitle:(NSString *)title {
......@@ -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,30 +535,26 @@
[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 {
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;
}
if (!_tableView) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!_tableView) {
CGFloat top = 0;
CGFloat tableViewHeight = 0;
if (self.navigationController.navigationBar.isTranslucent) {
......@@ -583,7 +577,9 @@
} 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,6 +71,15 @@ 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);
// [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;
......@@ -88,22 +97,26 @@ static CGSize AssetGridThumbnailSize;
[self initSubviews];
}
}
// [self resetCachedAssets];
});
}
- (void)initSubviews {
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