forked from QuintGao/GKPhotoBrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
272 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// GKPhotoManager.h | ||
// GKPhotoBrowserDemo | ||
// | ||
// Created by gaokun on 2020/6/16. | ||
// Copyright © 2020 QuintGao. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <Photos/Photos.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GKPhotoManager : NSObject | ||
|
||
+ (void)loadImageDataWithImageAsset:(PHAsset *)imageAsset completion:(nonnull void(^)(NSData *_Nullable data))completion; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// GKPhotoManager.m | ||
// GKPhotoBrowserDemo | ||
// | ||
// Created by gaokun on 2020/6/16. | ||
// Copyright © 2020 QuintGao. All rights reserved. | ||
// | ||
|
||
#import "GKPhotoManager.h" | ||
|
||
@implementation GKPhotoManager | ||
|
||
+ (void)loadImageDataWithImageAsset:(PHAsset *)imageAsset completion:(void (^)(NSData * _Nullable))completion { | ||
PHImageRequestOptions *options = [PHImageRequestOptions new]; | ||
options.networkAccessAllowed = YES; | ||
options.resizeMode = PHImageRequestOptionsResizeModeNone; | ||
options.synchronous = YES; | ||
[[PHImageManager defaultManager] requestImageDataForAsset:imageAsset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { | ||
BOOL complete = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey] && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue]; | ||
if (complete && imageData) { | ||
completion(imageData); | ||
} else { | ||
completion(nil); | ||
} | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/Main/WeChat/GKPublishViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// GKPublishViewController.h | ||
// GKPhotoBrowserDemo | ||
// | ||
// Created by gaokun on 2020/6/16. | ||
// Copyright © 2020 QuintGao. All rights reserved. | ||
// | ||
|
||
#import "GKBaseViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GKPublishViewController : GKBaseViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
96 changes: 96 additions & 0 deletions
96
GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/Main/WeChat/GKPublishViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// GKPublishViewController.m | ||
// GKPhotoBrowserDemo | ||
// | ||
// Created by gaokun on 2020/6/16. | ||
// Copyright © 2020 QuintGao. All rights reserved. | ||
// | ||
|
||
#import "GKPublishViewController.h" | ||
#import <TZImagePickerController/TZImagePickerController.h> | ||
#import "GKPhotosView.h" | ||
#import "GKPhotoBrowser.h" | ||
|
||
@interface GKPublishViewController ()<TZImagePickerControllerDelegate, GKPhotosViewDelegate> | ||
|
||
@property (nonatomic, strong) UIButton *selectBtn; | ||
|
||
@property (nonatomic, strong) GKPhotosView *photoView; | ||
|
||
@property (nonatomic, strong) NSArray *assets; | ||
|
||
@end | ||
|
||
@implementation GKPublishViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.gk_navTitle = @"发布"; | ||
self.view.backgroundColor = [UIColor whiteColor]; | ||
[self.view addSubview:self.selectBtn]; | ||
self.selectBtn.frame = CGRectMake((KScreenW - 80)/2, 100, 80, 30); | ||
|
||
[self.view addSubview:self.photoView]; | ||
self.photoView.frame = CGRectMake(0, 150, (kScreenW - 60 - 50 - 20), 0); | ||
} | ||
|
||
- (void)selectPhoto { | ||
TZImagePickerController *pickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self]; | ||
pickerVC.allowTakeVideo = NO; | ||
pickerVC.allowPickingVideo = NO; | ||
pickerVC.modalPresentationStyle = UIModalPresentationFullScreen; | ||
[self presentViewController:pickerVC animated:YES completion:nil]; | ||
} | ||
|
||
#pragma mark - TZImagePickerControllerDelegate | ||
- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker { | ||
|
||
} | ||
|
||
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto { | ||
self.assets = assets; | ||
|
||
self.photoView.photoImages = photos; | ||
|
||
CGFloat height = [GKPhotosView sizeWithCount:photos.count width:(kScreenW - 60 - 50 - 20) andMargin:5].height; | ||
self.photoView.frame = CGRectMake(0, 150, (kScreenW - 60 - 50 - 20), height); | ||
} | ||
|
||
#pragma mark - GKPhotosViewDelegate | ||
- (void)photoTapped:(UIImageView *)imgView { | ||
NSMutableArray *photos = [NSMutableArray new]; | ||
[self.assets enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | ||
GKPhoto *photo = [GKPhoto new]; | ||
photo.imageAsset = self.assets[idx]; | ||
photo.sourceImageView = self.photoView.subviews[idx]; | ||
[photos addObject:photo]; | ||
}]; | ||
|
||
GKPhotoBrowser *browser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:imgView.tag]; | ||
browser.showStyle = GKPhotoBrowserShowStyleZoom; | ||
browser.hideStyle = GKPhotoBrowserHideStyleZoomScale; | ||
browser.loadStyle = GKPhotoBrowserLoadStyleIndeterminateMask; | ||
[browser showFromVC:self]; | ||
} | ||
|
||
#pragma mark - 懒加载 | ||
- (UIButton *)selectBtn { | ||
if (!_selectBtn) { | ||
_selectBtn = [UIButton new]; | ||
[_selectBtn setTitle:@"选择图片" forState:UIControlStateNormal]; | ||
_selectBtn.backgroundColor = [UIColor redColor]; | ||
[_selectBtn addTarget:self action:@selector(selectPhoto) forControlEvents:UIControlEventTouchUpInside]; | ||
} | ||
return _selectBtn; | ||
} | ||
|
||
- (GKPhotosView *)photoView { | ||
if (!_photoView) { | ||
_photoView = [GKPhotosView photosViewWithWidth:(kScreenW - 60 - 50 - 20) andMargin:5]; | ||
_photoView.delegate = self; | ||
} | ||
return _photoView; | ||
} | ||
|
||
@end |
Oops, something went wrong.