Skip to content

Commit 32cd705

Browse files
committed
修复放大后滑动超过一张再返回后显示异常的问题#123
1 parent 0f3945d commit 32cd705

6 files changed

Lines changed: 36 additions & 36 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.2.1"
3+
s.version = "2.3.1"
44
s.summary = "iOS自定义图片浏览器,支持CocoaPods"
55
s.homepage = "https://github.com/QuintGao/GKPhotoBrowser"
66
s.license = "MIT"

GKPhotoBrowser/Core/GKPhotoBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ typedef void(^layoutBlock)(GKPhotoBrowser *photoBrowser, CGRect superFrame);
109109
@property (nonatomic, assign) BOOL isHideSourceView;
110110

111111
/// 滑动切换图片时,是否恢复上(下)一张图片的缩放程度,默认是NO
112+
/// 如果滑动超过一张,则恢复原状
112113
@property (nonatomic, assign) BOOL isResumePhotoZoom;
113114

114115
/// 横屏时是否充满屏幕宽度,默认YES,为NO时图片自动填充屏幕

GKPhotoBrowser/Core/GKPhotoView.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,12 @@ - (void)adjustFrame {
368368
self.loadingView.bounds = self.scrollView.frame;
369369
self.loadingView.center = CGPointMake(frame.size.width * 0.5, frame.size.height * 0.5);
370370
}
371+
371372

372373
// frame调整完毕,重新设置缩放
373374
if (self.photo.isZooming) {
375+
self.scrollView.maximumZoomScale = 1.0f;
376+
self.scrollView.zoomScale = 1.0f;
374377
[self zoomToRect:self.photo.zoomRect animated:NO];
375378
}
376379

@@ -386,12 +389,20 @@ - (CGPoint)centerOfScrollViewContent:(UIScrollView *)scrollView {
386389
}
387390

388391
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated {
389-
[self.scrollView zoomToRect:rect animated:YES];
392+
[self.scrollView zoomToRect:rect animated:animated];
390393
}
391394

392395
#pragma mark - UIScrollViewDelegate
393396
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
394-
self.photo.offset = scrollView.contentOffset;
397+
// 恢复位置
398+
if (self.photo.isZooming && scrollView.zoomScale == 1.0f) {
399+
scrollView.contentOffset = self.photo.offset;
400+
}
401+
402+
// 只在上下滑动时记录位置
403+
if (scrollView.zoomScale == 1.0f) {
404+
self.photo.offset = scrollView.contentOffset;
405+
}
395406
}
396407

397408
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
@@ -404,7 +415,6 @@ - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
404415

405416
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
406417
!self.zoomEnded ? : self.zoomEnded(self, scrollView.zoomScale);
407-
408418
[self setScrollMaxZoomScale:self.realZoomScale];
409419
}
410420

GKPhotoBrowserDemo/GKPhotoBrowserDemo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@
519519
795FA5831FF333420057BDB0 /* Project object */ = {
520520
isa = PBXProject;
521521
attributes = {
522-
LastUpgradeCheck = 1240;
522+
LastUpgradeCheck = 1250;
523523
ORGANIZATIONNAME = QuintGao;
524524
TargetAttributes = {
525525
795FA58A1FF333420057BDB0 = {

0 commit comments

Comments
 (0)