From f317f601197858be92f9203eee39c5a75673443b Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 13:25:24 +0400 Subject: [PATCH 1/7] new algorithm --- SKPhotoBrowser/SKZoomingScrollView.swift | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 883479b..3a25ea5 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -121,15 +121,31 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin let deviceScreenWidth = UIScreen.mainScreen().bounds.width let deviceScreenHeight = UIScreen.mainScreen().bounds.height + let scale = UIScreen.mainScreen().scale - if photoImageView.frame.width < deviceScreenWidth { +// if photoImageView.frame.width < deviceScreenWidth { +// // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. +// if UIApplication.sharedApplication().statusBarOrientation.isPortrait { +// maxScale = deviceScreenHeight / photoImageView.frame.width +// } else { +// maxScale = deviceScreenWidth / photoImageView.frame.width +// } +// } else if photoImageView.frame.width > deviceScreenWidth { +// maxScale = 1.0 +// } else { +// // here if photoImageView.frame.width == deviceScreenWidth +// maxScale = 2.5 +// } + if photoImageView.frame.width < deviceScreenWidth * scale { // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. if UIApplication.sharedApplication().statusBarOrientation.isPortrait { - maxScale = deviceScreenHeight / photoImageView.frame.width + print("first photoImageView.frame.width < deviceScreenHeight", deviceScreenHeight * scale / photoImageView.frame.width) + maxScale = deviceScreenHeight * scale / photoImageView.frame.width } else { - maxScale = deviceScreenWidth / photoImageView.frame.width + print("second photoImageView.frame.width < deviceScreenWidth", (deviceScreenWidth * scale) / photoImageView.frame.width) + maxScale = deviceScreenWidth * scale / photoImageView.frame.width } - } else if photoImageView.frame.width > deviceScreenWidth { + } else if photoImageView.frame.width > deviceScreenWidth * scale { maxScale = 1.0 } else { // here if photoImageView.frame.width == deviceScreenWidth From 8e31335272a9628e85c38e18608ec9d60210146c Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 14:26:14 +0400 Subject: [PATCH 2/7] stability for new algorithm --- SKPhotoBrowser/SKZoomingScrollView.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 3a25ea5..3ac7e80 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -119,9 +119,10 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin let minScale: CGFloat = min(xScale, yScale) var maxScale: CGFloat! - let deviceScreenWidth = UIScreen.mainScreen().bounds.width - let deviceScreenHeight = UIScreen.mainScreen().bounds.height + let scale = UIScreen.mainScreen().scale + let deviceScreenWidth = UIScreen.mainScreen().bounds.width * scale // width in pixels. scale needs to remove if to use the old algorithm + let deviceScreenHeight = UIScreen.mainScreen().bounds.height * scale // height in pixels. scale needs to remove if to use the old algorithm // if photoImageView.frame.width < deviceScreenWidth { // // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. @@ -136,16 +137,17 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin // // here if photoImageView.frame.width == deviceScreenWidth // maxScale = 2.5 // } - if photoImageView.frame.width < deviceScreenWidth * scale { + + if photoImageView.frame.width < deviceScreenWidth { // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. if UIApplication.sharedApplication().statusBarOrientation.isPortrait { - print("first photoImageView.frame.width < deviceScreenHeight", deviceScreenHeight * scale / photoImageView.frame.width) - maxScale = deviceScreenHeight * scale / photoImageView.frame.width + print("first photoImageView.frame.width < deviceScreenHeight", deviceScreenHeight / photoImageView.frame.width) + maxScale = deviceScreenHeight / photoImageView.frame.width } else { - print("second photoImageView.frame.width < deviceScreenWidth", (deviceScreenWidth * scale) / photoImageView.frame.width) - maxScale = deviceScreenWidth * scale / photoImageView.frame.width + print("second photoImageView.frame.width < deviceScreenWidth", (deviceScreenWidth) / photoImageView.frame.width) + maxScale = deviceScreenWidth / photoImageView.frame.width } - } else if photoImageView.frame.width > deviceScreenWidth * scale { + } else if photoImageView.frame.width > deviceScreenWidth { maxScale = 1.0 } else { // here if photoImageView.frame.width == deviceScreenWidth From 12f5bd9f23a6056f5c172efd6cdbdb42a3388cb1 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 14:50:19 +0400 Subject: [PATCH 3/7] to comment the old algorithm --- SKPhotoBrowser/SKZoomingScrollView.swift | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 3ac7e80..d5bccf7 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -124,19 +124,20 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin let deviceScreenWidth = UIScreen.mainScreen().bounds.width * scale // width in pixels. scale needs to remove if to use the old algorithm let deviceScreenHeight = UIScreen.mainScreen().bounds.height * scale // height in pixels. scale needs to remove if to use the old algorithm -// if photoImageView.frame.width < deviceScreenWidth { -// // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. -// if UIApplication.sharedApplication().statusBarOrientation.isPortrait { -// maxScale = deviceScreenHeight / photoImageView.frame.width -// } else { -// maxScale = deviceScreenWidth / photoImageView.frame.width -// } -// } else if photoImageView.frame.width > deviceScreenWidth { -// maxScale = 1.0 -// } else { -// // here if photoImageView.frame.width == deviceScreenWidth -// maxScale = 2.5 -// } + // it is the old algorithm + /* if photoImageView.frame.width < deviceScreenWidth { + // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. + if UIApplication.sharedApplication().statusBarOrientation.isPortrait { + maxScale = deviceScreenHeight / photoImageView.frame.width + } else { + maxScale = deviceScreenWidth / photoImageView.frame.width + } + } else if photoImageView.frame.width > deviceScreenWidth { + maxScale = 1.0 + } else { + // here if photoImageView.frame.width == deviceScreenWidth + maxScale = 2.5 + } */ if photoImageView.frame.width < deviceScreenWidth { // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. From 46554ec6c017ff843851c7ffd21779737dc88400 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 16:07:36 +0400 Subject: [PATCH 4/7] some changes --- SKPhotoBrowser/SKZoomingScrollView.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index d5bccf7..515ec3b 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -142,11 +142,11 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin if photoImageView.frame.width < deviceScreenWidth { // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. if UIApplication.sharedApplication().statusBarOrientation.isPortrait { - print("first photoImageView.frame.width < deviceScreenHeight", deviceScreenHeight / photoImageView.frame.width) + print("Portrait", deviceScreenHeight / photoImageView.frame.width) maxScale = deviceScreenHeight / photoImageView.frame.width } else { - print("second photoImageView.frame.width < deviceScreenWidth", (deviceScreenWidth) / photoImageView.frame.width) - maxScale = deviceScreenWidth / photoImageView.frame.width + print("landscape", (deviceScreenWidth) / photoImageView.frame.width) + maxScale = deviceScreenWidth / photoImageView.frame.width } } else if photoImageView.frame.width > deviceScreenWidth { maxScale = 1.0 @@ -161,7 +161,7 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin // on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the // maximum zoom scale to 0.5 - maxScale = maxScale / UIScreen.mainScreen().scale + maxScale = maxScale / scale if maxScale < minScale { maxScale = minScale * 2 } @@ -209,7 +209,7 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin setMaxMinZoomScalesForCurrentBounds() } - + print(photoImageView.frame) setNeedsLayout() } @@ -305,6 +305,7 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin } func handleImageViewDoubleTap(view: UIImageView, touch: UITouch) { + print(photoImageView.frame) handleDoubleTap(touch.locationInView(view)) } } \ No newline at end of file From 1af051b8a24fa169eb73d08e066287eb305855eb Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 18:14:12 +0400 Subject: [PATCH 5/7] I think that the result should be the same after double touch or pinch, it was different --- SKPhotoBrowser/SKZoomingScrollView.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 515ec3b..05b6f98 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -142,11 +142,9 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin if photoImageView.frame.width < deviceScreenWidth { // I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations. if UIApplication.sharedApplication().statusBarOrientation.isPortrait { - print("Portrait", deviceScreenHeight / photoImageView.frame.width) maxScale = deviceScreenHeight / photoImageView.frame.width } else { - print("landscape", (deviceScreenWidth) / photoImageView.frame.width) - maxScale = deviceScreenWidth / photoImageView.frame.width + maxScale = deviceScreenWidth / photoImageView.frame.width } } else if photoImageView.frame.width > deviceScreenWidth { maxScale = 1.0 @@ -161,10 +159,13 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin // on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the // maximum zoom scale to 0.5 + // After changing this value, we still never use more + /* maxScale = maxScale / scale if maxScale < minScale { maxScale = minScale * 2 } + */ // reset position photoImageView.frame = CGRect(x: 0, y: 0, width: photoImageView.frame.size.width, height: photoImageView.frame.size.height) @@ -209,7 +210,6 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin setMaxMinZoomScalesForCurrentBounds() } - print(photoImageView.frame) setNeedsLayout() } @@ -228,12 +228,13 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin setZoomScale(minimumZoomScale, animated: true) } else { // zoom in - var newZoom: CGFloat = zoomScale * 3.13 + // I think that the result should be the same after double touch or pinch + /* var newZoom: CGFloat = zoomScale * 3.13 if newZoom >= maximumZoomScale { newZoom = maximumZoomScale } - - zoomToRect(zoomRectForScrollViewWith(newZoom, touchPoint:touchPoint), animated:true) + */ + zoomToRect(zoomRectForScrollViewWith(maximumZoomScale, touchPoint: touchPoint), animated: true) } // delay control @@ -305,7 +306,6 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin } func handleImageViewDoubleTap(view: UIImageView, touch: UITouch) { - print(photoImageView.frame) handleDoubleTap(touch.locationInView(view)) } } \ No newline at end of file From 9777879583f9d05ee1fedc4d2c8664dc02a1f2c0 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 18:41:13 +0400 Subject: [PATCH 6/7] here was a mistake, when we opened the browser, and then turned the device activity light remained in the same place that looked incorrectly https://www.dropbox.com/s/mc55lvapyqaetpo/Simulator%20Screen%20Shot%20Apr%205%2C%202016%2C%202.29.37%20PM.png?dl=0 --- SKPhotoBrowser/SKIndicatorView.swift | 2 +- SKPhotoBrowser/SKZoomingScrollView.swift | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/SKPhotoBrowser/SKIndicatorView.swift b/SKPhotoBrowser/SKIndicatorView.swift index a7988df..fa6ff9d 100644 --- a/SKPhotoBrowser/SKIndicatorView.swift +++ b/SKPhotoBrowser/SKIndicatorView.swift @@ -16,7 +16,7 @@ class SKIndicatorView: UIActivityIndicatorView { override init(frame: CGRect) { super.init(frame: frame) - center = CGPoint(x: frame.width/2, y: frame.height/2) + center = CGPoint(x: frame.width / 2, y: frame.height / 2) activityIndicatorViewStyle = .WhiteLarge } diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 05b6f98..d0b6dea 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -74,9 +74,13 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin } // MARK: - override + public override func layoutSubviews() { tapView.frame = bounds + // + indicatorView.frame = frame + super.layoutSubviews() let boundsSize = bounds.size From 3a399a85d71eae33713ff864195cbb057c626ba3 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Tue, 5 Apr 2016 18:44:58 +0400 Subject: [PATCH 7/7] update podspec --- SKPhotoBrowser.podspec | 2 +- SKPhotoBrowser/SKZoomingScrollView.swift | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SKPhotoBrowser.podspec b/SKPhotoBrowser.podspec index 472ae86..5f18d9d 100644 --- a/SKPhotoBrowser.podspec +++ b/SKPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SKPhotoBrowser" - s.version = "1.8.0" + s.version = "1.8.1" s.summary = "Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift2.0." s.homepage = "https://github.com/suzuki-0000/SKPhotoBrowser" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index d0b6dea..3db6fbc 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -77,8 +77,6 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin public override func layoutSubviews() { tapView.frame = bounds - - // indicatorView.frame = frame super.layoutSubviews()