Skip to content

Commit ebc8466

Browse files
committed
bug修复及优化,发布2.4.1版本
1、修复屏幕旋转bug #149 2、新增addNavigationController属性,可在显示图片浏览器后push到新的控制器
1 parent 72745fb commit ebc8466

8 files changed

Lines changed: 76 additions & 32 deletions

File tree

GKPhotoBrowser.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "GKPhotoBrowser"
3-
s.version = "2.4.0"
3+
s.version = "2.4.1"
44
s.summary = "iOS自定义图片浏览器,支持CocoaPods"
55
s.homepage = "https://github.com/QuintGao/GKPhotoBrowser"
66
s.license = "MIT"

GKPhotoBrowser/Core/GKPhotoBrowser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ typedef void(^layoutBlock)(GKPhotoBrowser *photoBrowser, CGRect superFrame);
152152
@property (nonatomic, copy) NSString *failureText;
153153
@property (nonatomic, strong) UIImage *failureImage;
154154

155+
/// 是否添加导航控制器,默认NO,添加后会默认隐藏导航栏
156+
/// showStyle = GKPhotoBrowserShowStylePush时无效
157+
@property (nonatomic, assign, getter=isAddNavigationController) BOOL addNavigationController;
158+
155159
// 初始化方法
156160

157161
/**

GKPhotoBrowser/Core/GKPhotoBrowser.m

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ - (void)viewDidDisappear:(BOOL)animated {
198198
}
199199

200200
- (void)setupUI {
201-
if (!self.navigationController.navigationBarHidden && !self.navigationController.navigationBar.hidden) {
201+
if (!self.navigationController.navigationBarHidden) {
202202
[self.navigationController setNavigationBarHidden:YES];
203203
}
204204

@@ -278,15 +278,6 @@ - (void)addGestureAndObserver {
278278
}
279279

280280
#pragma mark - Setter
281-
- (void)setShowStyle:(GKPhotoBrowserShowStyle)showStyle {
282-
_showStyle = showStyle;
283-
284-
if (showStyle != GKPhotoBrowserShowStylePush) {
285-
self.modalPresentationStyle = UIModalPresentationCustom;
286-
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
287-
}
288-
}
289-
290281
- (void)setIsStatusBarShow:(BOOL)isStatusBarShow {
291282
_isStatusBarShow = isStatusBarShow;
292283

@@ -492,8 +483,18 @@ - (void)showFromVC:(UIViewController *)vc {
492483
if (self.showStyle == GKPhotoBrowserShowStylePush) {
493484
[vc.navigationController pushViewController:self animated:YES];
494485
}else {
495-
self.modalPresentationCapturesStatusBarAppearance = YES;
496-
[vc presentViewController:self animated:NO completion:nil];
486+
if (self.isAddNavigationController) {
487+
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
488+
nav.modalPresentationCapturesStatusBarAppearance = YES;
489+
nav.modalPresentationStyle = UIModalPresentationCustom;
490+
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
491+
[vc presentViewController:nav animated:NO completion:nil];
492+
}else {
493+
self.modalPresentationCapturesStatusBarAppearance = YES;
494+
self.modalPresentationStyle = UIModalPresentationCustom;
495+
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
496+
[vc presentViewController:self animated:NO completion:nil];
497+
}
497498
}
498499
}
499500

@@ -1349,6 +1350,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
13491350
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
13501351
if (!self.isFollowSystemRotation) return;
13511352

1353+
self.isRotation = YES;
13521354
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
13531355
[UIView animateWithDuration:0.3 animations:^{
13541356
CGFloat width = self.view.bounds.size.width;
@@ -1367,6 +1369,8 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi
13671369
[self.view setNeedsLayout];
13681370
[self.view layoutIfNeeded];
13691371
[self layoutSubviews];
1372+
} completion:^(BOOL finished) {
1373+
self.isRotation = NO;
13701374
}];
13711375
});
13721376
}

GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ - (void)applicationWillTerminate:(UIApplication *)application {
9393
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
9494
}
9595

96-
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
97-
return UIInterfaceOrientationMaskPortrait;
98-
}
96+
//- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
97+
// return UIInterfaceOrientationMaskPortrait;
98+
//}
9999

100100
@end

GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/Main/GKMainViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ - (void)setupData {
6363
@"class" : @"GKSDAutoLayoutViewController"},
6464
@{@"text" : @"GIF图片",
6565
@"class" : @"GKGIFViewController"},
66-
// @{@"text" : @"测试",
67-
// @"class" : @"GKTestViewController"},
66+
@{@"text" : @"测试",
67+
@"class" : @"GKTestViewController"},
6868
];
6969

7070
[self.mainTable reloadData];

GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/Main/Test/GKTestViewController.m

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "GKTestViewController.h"
1010
#import "GKTest02ViewCell.h"
1111
#import "GKBottomView.h"
12-
1312
#import "GKPhotoBrowser.h"
1413

1514
@interface GKTestViewController ()<UITableViewDataSource, UITableViewDelegate, GKPhotoBrowserDelegate>
@@ -22,6 +21,8 @@ @interface GKTestViewController ()<UITableViewDataSource, UITableViewDelegate, G
2221

2322
@property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
2423

24+
@property (nonatomic, weak) GKPhotoBrowser *browser;
25+
2526
@end
2627

2728
@implementation GKTestViewController
@@ -33,12 +34,12 @@ - (void)viewDidLoad {
3334
self.view.backgroundColor = [UIColor whiteColor];
3435

3536

36-
GKBottomView *btmView = [GKBottomView new];
37-
btmView.frame = CGRectMake(0, 100, self.view.frame.size.width, 100);
38-
[self.view addSubview:btmView];
39-
// [self setupView];
40-
//
41-
// [self setupData];
37+
// GKBottomView *btmView = [GKBottomView new];
38+
// btmView.frame = CGRectMake(0, 100, self.view.frame.size.width, 100);
39+
// [self.view addSubview:btmView];
40+
[self setupView];
41+
42+
[self setupData];
4243
}
4344

4445
- (void)setupView {
@@ -54,7 +55,12 @@ - (void)setupView {
5455

5556
- (void)setupData {
5657

57-
self.dataSource = @[@[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536686&di=aa91a60dfb4f9f762f58bb4513f9ef64&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F50da81cb39dbb6fd493c67e70024ab18962b378f.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=3b472d84a7801f2fd48afaa4f041fadb&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F0824ab18972bd40704fe413d72899e510fb30930.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=18fcb83dcc07f87aefbf58e8538ed4d8&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fd1160924ab18972b22abd40aefcd7b899f510a59.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=b40f1593ca5f51f64c8f8670598e79a2&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fcrop%253D0%252C0%252C1024%252C654%2Fsign%3Dafc45f018b025aafc77d248bc6dd8754%2F838ba61ea8d3fd1f3fe3bbfb394e251f94ca5f0c.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=a47731fce0273aae3ddeb03d89fc273b&imgtype=0&src=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fb7003af33a87e950f0e956ad19385343faf2b471.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=121d9ff529f2d9807970f965aeca6c0f&imgtype=0&src=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F241f95cad1c8a7861cb6a3ce6e09c93d71cf5056.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536685&di=a82dd1f57162599367340d0b5a9ece74&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fae51f3deb48f8c546c9162ee33292df5e1fe7fb5.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536684&di=22258dd90dec8f57bdeea79f8c17b04f&imgtype=0&src=http%3A%2F%2Fc.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F0d338744ebf81a4c1393d808de2a6059242da649.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509084536684&di=16dfed673e74c9e5f1c53e02700ab174&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fd058ccbf6c81800a6d5592cfb83533fa838b47ba.jpg"]
58+
self.dataSource = @[@[@"http://p1.music.126.net/9k3CAPfB9WdcMCFk4CYnKQ==/109951167793871917.jpg?imageView&quality=89",
59+
@"http://p1.music.126.net/GK7JvutM88U4ZkohN71TKQ==/109951167794081491.jpg?imageView&quality=89",
60+
// @"http://p1.music.126.net/QywPBMy3VK-P-wk_eYjrZw==/109951167793910298.jpg?imageView&quality=89",
61+
// @"http://p1.music.126.net/c4vOjlBA5bQsmpuASPi5QQ==/109951167794545716.jpg?imageView&quality=89",
62+
// @"http://p1.music.126.net/4ryVvqlvXp0Kh_fcxCWMsA==/109951166903789195.jpg?param=140y140",
63+
@"http://p1.music.126.net/gZWQbChzhCbGFXtpin2MXw==/109951167592864239.jpg?param=140y140"]
5864
];
5965

6066
[self.tableView reloadData];
@@ -89,11 +95,25 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
8995
// browser.currentIndex = index;
9096
browser.showStyle = GKPhotoBrowserShowStyleZoom;
9197
browser.hideStyle = GKPhotoBrowserHideStyleZoomScale;
92-
[browser setupCoverViews:@[self.coverView] layoutBlock:^(GKPhotoBrowser * _Nonnull photoBrowser, CGRect superFrame) {
93-
self.coverView.frame = CGRectMake(0, 200, superFrame.size.width, 100);
98+
browser.isFollowSystemRotation = YES;
99+
browser.addNavigationController = YES;
100+
101+
UIButton *btn = [[UIButton alloc] init];
102+
[btn setImage:[UIImage imageNamed:@"cm2_list_detail_icn_cmt"] forState:UIControlStateNormal];
103+
[btn sizeToFit];
104+
105+
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
106+
107+
[browser setupCoverViews:@[btn] layoutBlock:^(GKPhotoBrowser * _Nonnull photoBrowser, CGRect superFrame) {
108+
CGRect frame = btn.frame;
109+
frame.origin.x = superFrame.size.width - frame.size.width - 30;
110+
frame.origin.y = superFrame.size.height - frame.size.height - 30;
111+
btn.frame = frame;
94112
}];
95113

114+
browser.delegate = self;
96115
[browser showFromVC:self];
116+
self.browser = browser;
97117
};
98118

99119
return cell;
@@ -110,6 +130,18 @@ - (void)pangesture:(UIPanGestureRecognizer *)pan {
110130

111131
}
112132

133+
- (void)btnClick {
134+
UIViewController *vc = [[UIViewController alloc] init];
135+
vc.view.backgroundColor = UIColor.grayColor;
136+
[self.browser.navigationController setNavigationBarHidden:NO];
137+
[self.browser.navigationController pushViewController:vc animated:YES];
138+
}
139+
140+
#pragma mark - GKPhotoBrowserDelegate
141+
- (void)photoBrowser:(GKPhotoBrowser *)browser didDisappearAtIndex:(NSInteger)index {
142+
143+
}
144+
113145
#pragma mark - 懒加载
114146
- (UIView *)coverView {
115147
if (!_coverView) {

GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/Main/WeChat/GKTimeLineViewController.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
135135
// browser.bgColor = UIColor.whiteColor;
136136
// browser.statusBarStyle = UIStatusBarStyleDefault;
137137

138-
// 当你的APP支持屏幕旋转时此属性必须设置为YES
139-
if (kIsiPad) { // ipad 默认支持屏幕旋转,这里设置为YES
140-
browser.isFollowSystemRotation = YES;
141-
}
138+
// // 当你的APP支持屏幕旋转时此属性必须设置为YES
139+
// if (kIsiPad) { // ipad 默认支持屏幕旋转,这里设置为YES
140+
// browser.isFollowSystemRotation = YES;
141+
// }
142142
// [browser setupWebImageProtocol:[[GKYYWebImageManager alloc] init]];
143+
144+
browser.isFollowSystemRotation = YES;
143145
browser.delegate = weakSelf;
144146
[browser showFromVC:weakSelf];
145147
weakSelf.browser = browser;

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ GKPhotoBrowser一个可高度自定义的图片浏览器,demo里面实现的
100100
## 更新
101101

102102
```
103+
2022.08.19 2.4.1版本,1、修复屏幕旋转bug #149
104+
2、新增addNavigationController,可在显示图片浏览器后push到新的控制器
103105
2022.07.27 2.4.0版本,修复横屏后屏幕朝上自动变为竖屏的问题 #147
104106
2022.04.07 2.3.8版本,优化代码,修复bug #138
105107
2022.03.25 2.3.7版本,新增animDuration属性,可自定义动画时间

0 commit comments

Comments
 (0)