From 31e3378c9a91f43e8831b210b7c234203363ba03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Bu=CC=88hmann?= Date: Wed, 24 Aug 2016 12:18:50 +0200 Subject: [PATCH 1/4] Improve compile time significantly by adding types --- SKPhotoBrowser/SKPhotoBrowser.swift | 42 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index d1fa89c..7681137 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -717,12 +717,12 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // MARK: - panGestureRecognized public func panGestureRecognized(sender: UIPanGestureRecognizer) { backgroundView.hidden = true - let scrollView = pageDisplayedAtIndex(currentPageIndex) + let scrollView: SKZoomingScrollView = pageDisplayedAtIndex(currentPageIndex) - let viewHeight = scrollView.frame.size.height - let viewHalfHeight = viewHeight/2 + let viewHeight: CGFloat = scrollView.frame.size.height + let viewHalfHeight: CGFloat = viewHeight/2 - var translatedPoint = sender.translationInView(self.view) + var translatedPoint: CGPoint = sender.translationInView(self.view) // gesture began if sender.state == .Began { @@ -738,8 +738,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { translatedPoint = CGPoint(x: firstX, y: firstY + translatedPoint.y) scrollView.center = translatedPoint - let minOffset = viewHalfHeight / 4 - let offset = 1 - (scrollView.center.y > viewHalfHeight ? scrollView.center.y - viewHalfHeight : -(scrollView.center.y - viewHalfHeight)) / viewHalfHeight + let minOffset: CGFloat = viewHalfHeight / 4 + let offset: CGFloat = 1 - (scrollView.center.y > viewHalfHeight ? scrollView.center.y - viewHalfHeight : -(scrollView.center.y - viewHalfHeight)) / viewHalfHeight view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(max(0.7, offset)) // gesture end @@ -757,10 +757,10 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { let finalX: CGFloat = firstX let finalY: CGFloat = viewHalfHeight - let animationDuration = Double(abs(velocityY) * 0.0002 + 0.2) + let animationDuration: CGFloat = abs(velocityY) * 0.0002 + 0.2 UIView.beginAnimations(nil, context: nil) - UIView.setAnimationDuration(animationDuration) + UIView.setAnimationDuration(Double(animationDuration)) UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn) view.backgroundColor = UIColor.blackColor() scrollView.center = CGPoint(x: finalX, y: finalY) @@ -995,13 +995,18 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { } public func tilePages() { - let visibleBounds = pagingScrollView.bounds + let visibleBounds: CGRect = pagingScrollView.bounds - var firstIndex = Int(floor((CGRectGetMinX(visibleBounds) + 10 * 2) / CGRectGetWidth(visibleBounds))) - var lastIndex = Int(floor((CGRectGetMaxX(visibleBounds) - 10 * 2 - 1) / CGRectGetWidth(visibleBounds))) + let visibleWidth: CGFloat = CGRectGetWidth(visibleBounds) + let firstIndexFloat: CGFloat = (CGRectGetMinX(visibleBounds) + 10 * 2) / visibleWidth + let lastIndexFloat: CGFloat = (CGRectGetMaxX(visibleBounds) - 10 * 2 - 1) / visibleWidth + var firstIndex: Int = Int(floor(firstIndexFloat)) + var lastIndex: Int = Int(floor(lastIndexFloat)) if firstIndex < 0 { firstIndex = 0 } + + let numberOfPhotos: Int = self.numberOfPhotos if firstIndex > numberOfPhotos - 1 { firstIndex = numberOfPhotos - 1 } @@ -1012,8 +1017,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { lastIndex = numberOfPhotos - 1 } - for page in visiblePages { - let newPageIndex = page.tag - pageIndexTagOffset + for page: SKZoomingScrollView in visiblePages { + let newPageIndex: Int = page.tag - pageIndexTagOffset if newPageIndex < firstIndex || newPageIndex > lastIndex { recycledPages.append(page) page.prepareForReuse() @@ -1021,19 +1026,20 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { } } - let visibleSet = Set(visiblePages) - visiblePages = Array(visibleSet.subtract(recycledPages)) + let visibleSet: Set = Set(visiblePages) + let visibleSetWithoutRecycled: Set = visibleSet.subtract(recycledPages) + visiblePages = Array(visibleSetWithoutRecycled) while recycledPages.count > 2 { recycledPages.removeFirst() } - for index in firstIndex...lastIndex { + for index: Int in firstIndex...lastIndex { if isDisplayingPageForIndex(index) { continue } - let page = SKZoomingScrollView(frame: view.frame, browser: self) + let page: SKZoomingScrollView = SKZoomingScrollView(frame: view.frame, browser: self) page.frame = frameForPageAtIndex(index) page.tag = index + pageIndexTagOffset page.photo = photoAtIndex(index) @@ -1041,7 +1047,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { visiblePages.append(page) pagingScrollView.addSubview(page) // if exists caption, insert - if let captionView = captionViewForPhotoAtIndex(index) { + if let captionView: SKCaptionView = captionViewForPhotoAtIndex(index) { captionView.frame = frameForCaptionView(captionView, index: index) pagingScrollView.addSubview(captionView) // ref val for control From 0d0aa326daf46e2a0f951159ea5330a0feb4d7ee Mon Sep 17 00:00:00 2001 From: suzuki_keishi Date: Thu, 25 Aug 2016 12:53:44 +0900 Subject: [PATCH 2/4] compile-time-optimization. --- SKPhotoBrowser.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SKPhotoBrowser.podspec b/SKPhotoBrowser.podspec index b13694c..3aaca65 100644 --- a/SKPhotoBrowser.podspec +++ b/SKPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SKPhotoBrowser" - s.version = "2.0.2" + s.version = "2.0.3" 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" } From 4a76fa9b30ed3519058fe10a9bcd26c6cb3f3733 Mon Sep 17 00:00:00 2001 From: Gustavo Gervasio Date: Mon, 29 Aug 2016 14:39:39 -0300 Subject: [PATCH 3/4] add support to swift 2.3 --- SKPhotoBrowser.xcodeproj/project.pbxproj | 3 +++ SKPhotoBrowser/SKPhotoBrowser.swift | 2 +- SKPhotoBrowser/extensions/UIImage+Rotation.swift | 14 +++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/SKPhotoBrowser.xcodeproj/project.pbxproj b/SKPhotoBrowser.xcodeproj/project.pbxproj index f1ec711..0c7f538 100644 --- a/SKPhotoBrowser.xcodeproj/project.pbxproj +++ b/SKPhotoBrowser.xcodeproj/project.pbxproj @@ -199,6 +199,7 @@ TargetAttributes = { 8909B52F1BC791280060A053 = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0800; }; A64B89321CB04222000071B9 = { CreatedOnToolsVersion = 7.3; @@ -402,6 +403,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 2.3; }; name = Debug; }; @@ -420,6 +422,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.SKPhotoBrowser; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 2.3; }; name = Release; }; diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 7681137..4b91e79 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -948,7 +948,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { sender.layer.renderInContext(UIGraphicsGetCurrentContext()!) let result = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() - return result + return result! } // MARK: - paging diff --git a/SKPhotoBrowser/extensions/UIImage+Rotation.swift b/SKPhotoBrowser/extensions/UIImage+Rotation.swift index 09ed323..be342a6 100644 --- a/SKPhotoBrowser/extensions/UIImage+Rotation.swift +++ b/SKPhotoBrowser/extensions/UIImage+Rotation.swift @@ -52,21 +52,21 @@ extension UIImage { // Now we draw the underlying CGImage into a new context, applying the transform // calculated above. let ctx = CGBitmapContextCreate(nil, Int(self.size.width), Int(self.size.height), - CGImageGetBitsPerComponent(self.CGImage), 0, - CGImageGetColorSpace(self.CGImage), - CGImageGetBitmapInfo(self.CGImage).rawValue) - CGContextConcatCTM(ctx, transform) + CGImageGetBitsPerComponent(self.CGImage!), 0, + CGImageGetColorSpace(self.CGImage!)!, + CGImageGetBitmapInfo(self.CGImage!).rawValue) + CGContextConcatCTM(ctx!, transform) switch self.imageOrientation { case .Left, .LeftMirrored, .Right, .RightMirrored: - CGContextDrawImage(ctx, CGRect(x: 0, y: 0, width: size.height, height: size.width), self.CGImage) + CGContextDrawImage(ctx!, CGRect(x: 0, y: 0, width: size.height, height: size.width), self.CGImage!) default: - CGContextDrawImage(ctx, CGRect(x: 0, y: 0, width: size.width, height: size.height), self.CGImage) + CGContextDrawImage(ctx!, CGRect(x: 0, y: 0, width: size.width, height: size.height), self.CGImage!) } // And now we just create a new UIImage from the drawing context - if let cgImage = CGBitmapContextCreateImage(ctx) { + if let cgImage = CGBitmapContextCreateImage(ctx!) { return UIImage(CGImage: cgImage) } else { return self From b4d911bee3126bce7c2634f36e47074d256eec81 Mon Sep 17 00:00:00 2001 From: suzuki_keishi Date: Tue, 30 Aug 2016 16:04:07 +0900 Subject: [PATCH 4/4] update podspec for swift2.3 --- SKPhotoBrowser.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SKPhotoBrowser.podspec b/SKPhotoBrowser.podspec index 3aaca65..0cc9617 100644 --- a/SKPhotoBrowser.podspec +++ b/SKPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SKPhotoBrowser" - s.version = "2.0.3" + s.version = "2.0.4" 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" }