From a9c89dd09eaf00ebaa63eab698bcd5962ace369c Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 14:28:01 +0400 Subject: [PATCH 1/9] Added recycledPages --- SKPhotoBrowser/SKPhotoBrowser.swift | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 14c7c23..42e7e20 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -100,6 +100,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // photo's paging private var visiblePages = [SKZoomingScrollView]()//: Set = Set() + private var recycledPages = [SKZoomingScrollView]() + private var initialPageIndex: Int = 0 private var currentPageIndex: Int = 0 @@ -325,6 +327,11 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { } } + public override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + recycledPages.removeAll() + } + // MARK: - set startap values private func setStartupValue() { startOrientation = UIApplication.sharedApplication().statusBarOrientation.rawValue @@ -512,6 +519,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // reset local cache visiblePages.removeAll() + recycledPages.removeAll() // set content offset pagingScrollView.contentOffset = contentOffsetForPageAtIndex(currentPageIndex) @@ -945,6 +953,27 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { lastIndex = numberOfPhotos - 1 } + // + for page in visiblePages { + if let pageIndex = visiblePages.indexOf(page) { + if (pageIndex < firstIndex || pageIndex > lastIndex) { + recycledPages.append(page) + page.prepareForReuse() //TODO: - it need to change + page.removeFromSuperview() + print("Removed page at index \(pageIndex)") + } + } + } + + let visibleSet = Set(visiblePages) + visiblePages = Array(visibleSet.subtract(recycledPages)) + + while (recycledPages.count > 2) { + recycledPages.removeFirst() + } + + + // for var index = firstIndex; index <= lastIndex; index++ { if isDisplayingPageForIndex(index) { continue @@ -958,7 +987,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // visiblePages.insert(page) visiblePages.append(page) pagingScrollView.addSubview(page) - + print("Page added at index \(index)") // if exists caption, insert if let captionView = captionViewForPhotoAtIndex(index) { captionView.frame = frameForCaptionView(captionView, index: index) From 79f672711b69773cde17acc5752d07aaecf2e720 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 14:34:53 +0400 Subject: [PATCH 2/9] Changed prepareForReuse function. I added SKPhotoBrowser.framework in the SKPhotoBrowserExample in the Embed frameworks that we can to test on a real device. If I don't add it in the Embed Frameworks I get the "Reason Image" error. --- SKPhotoBrowser/SKPhotoBrowser.swift | 2 +- SKPhotoBrowser/SKZoomingScrollView.swift | 4 ++ .../project.pbxproj | 38 ++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 42e7e20..614bc38 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -958,7 +958,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if let pageIndex = visiblePages.indexOf(page) { if (pageIndex < firstIndex || pageIndex > lastIndex) { recycledPages.append(page) - page.prepareForReuse() //TODO: - it need to change +// page.prepareForReuse() //TODO: - it need to change page.removeFromSuperview() print("Removed page at index \(pageIndex)") } diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index ed81c90..c06f72e 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -146,6 +146,10 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin public func prepareForReuse() { photo = nil + if captionView != nil { + captionView.removeFromSuperview() + captionView = nil + } } // MARK: - image diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj index 207af69..f89141a 100644 --- a/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 8909B5601BC792150060A053 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8909B55E1BC792150060A053 /* Main.storyboard */; }; 8909B5621BC792150060A053 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5611BC792150060A053 /* Assets.xcassets */; }; 8909B5651BC792150060A053 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5631BC792150060A053 /* LaunchScreen.storyboard */; }; - 8909B5731BC792AF0060A053 /* SKPhotoBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5711BC792570060A053 /* SKPhotoBrowser.framework */; }; 8909B5811BC792DC0060A053 /* image0.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5751BC792DC0060A053 /* image0.jpg */; }; 8909B5821BC792DC0060A053 /* image1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5761BC792DC0060A053 /* image1.jpg */; }; 8909B5831BC792DC0060A053 /* image10.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5771BC792DC0060A053 /* image10.jpg */; }; @@ -25,6 +24,8 @@ 8909B58A1BC792DC0060A053 /* image7.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B57E1BC792DC0060A053 /* image7.jpg */; }; 8909B58B1BC792DC0060A053 /* image8.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B57F1BC792DC0060A053 /* image8.jpg */; }; 8909B58C1BC792DC0060A053 /* image9.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 8909B5801BC792DC0060A053 /* image9.jpg */; }; + A6A7B7801C9578E30025AC07 /* SKPhotoBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5711BC792570060A053 /* SKPhotoBrowser.framework */; }; + A6A7B7811C9578E30025AC07 /* SKPhotoBrowser.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5711BC792570060A053 /* SKPhotoBrowser.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -35,8 +36,29 @@ remoteGlobalIDString = 8909B5301BC791280060A053; remoteInfo = SKPhotoBrowser; }; + A6A7B7821C9578E30025AC07 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8909B56C1BC792570060A053 /* SKPhotoBrowser.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 8909B52F1BC791280060A053; + remoteInfo = SKPhotoBrowser; + }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + A6A7B7841C9578E30025AC07 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + A6A7B7811C9578E30025AC07 /* SKPhotoBrowser.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 8909B5571BC792150060A053 /* SKPhotoBrowserExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SKPhotoBrowserExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8909B55A1BC792150060A053 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -65,7 +87,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8909B5731BC792AF0060A053 /* SKPhotoBrowser.framework in Frameworks */, + A6A7B7801C9578E30025AC07 /* SKPhotoBrowser.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -140,10 +162,12 @@ 8909B5531BC792150060A053 /* Sources */, 8909B5541BC792150060A053 /* Frameworks */, 8909B5551BC792150060A053 /* Resources */, + A6A7B7841C9578E30025AC07 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( + A6A7B7831C9578E30025AC07 /* PBXTargetDependency */, ); name = SKPhotoBrowserExample; productName = SKPhotoBrowserExample; @@ -235,6 +259,14 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + A6A7B7831C9578E30025AC07 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SKPhotoBrowser; + targetProxy = A6A7B7821C9578E30025AC07 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 8909B55E1BC792150060A053 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -342,6 +374,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SKPhotoBrowserExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.SKPhotoBrowserExample; @@ -353,6 +386,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SKPhotoBrowserExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.SKPhotoBrowserExample; From 2bc9c33c6052474d1048408ae03303b2f340baab Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 14:53:12 +0400 Subject: [PATCH 3/9] I changed var photo in SKZoomingScrollView and we now can to use prepareForReuse and we don't get the optional value error --- SKPhotoBrowser/SKPhotoBrowser.swift | 2 +- SKPhotoBrowser/SKZoomingScrollView.swift | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 614bc38..42e7e20 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -958,7 +958,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if let pageIndex = visiblePages.indexOf(page) { if (pageIndex < firstIndex || pageIndex > lastIndex) { recycledPages.append(page) -// page.prepareForReuse() //TODO: - it need to change + page.prepareForReuse() //TODO: - it need to change page.removeFromSuperview() print("Removed page at index \(pageIndex)") } diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index c06f72e..469d2d2 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -14,7 +14,9 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin var photo: SKPhotoProtocol! { didSet { photoImageView.image = nil - displayImage() + if photo != nil { + displayImage() + } } } From 22fbd1a00d07bf8782fbc93688baff32800f18c9 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 16:00:36 +0400 Subject: [PATCH 4/9] force tile pages when view isn't active and remove todo of prepareForReuse --- SKPhotoBrowser/SKPhotoBrowser.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 42e7e20..c5055d9 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -903,7 +903,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if isViewLoaded() { jumpToPageAtIndex(index) - if isViewActive { + if !isViewActive { tilePages() } } @@ -958,7 +958,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if let pageIndex = visiblePages.indexOf(page) { if (pageIndex < firstIndex || pageIndex > lastIndex) { recycledPages.append(page) - page.prepareForReuse() //TODO: - it need to change + page.prepareForReuse() page.removeFromSuperview() print("Removed page at index \(pageIndex)") } From 82aced57c3b6b75ecb3853ace423f4d22943e309 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 16:45:14 +0400 Subject: [PATCH 5/9] I removed no longer needed the value and the function --- SKPhotoBrowser/SKPhotoBrowser.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index c5055d9..3606660 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -118,7 +118,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { private var isViewActive: Bool = false private var isPerformingLayout: Bool = false private var isStatusBarOriginallyHidden: Bool = false - private var startOrientation: Int! // scroll property private var firstX: CGFloat = 0.0 @@ -247,7 +246,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { toolCounterButton = UIBarButtonItem(customView: toolCounterLabel) // starting setting - setStartupValue() setCustomSetting() setSettingCloseButton() setSettingDeleteButton() @@ -333,9 +331,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { } // MARK: - set startap values - private func setStartupValue() { - startOrientation = UIApplication.sharedApplication().statusBarOrientation.rawValue - } // MARK: - setting of buttons // This function should be at the beginning of the other functions From 8bdb4270f2fe5742faeac1c725d901ef5a61a673 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 17:56:07 +0400 Subject: [PATCH 6/9] it works with first image --- SKPhotoBrowser/SKPhotoBrowser.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 3606660..444e3c5 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -950,7 +950,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // for page in visiblePages { - if let pageIndex = visiblePages.indexOf(page) { + if let pageIndex: Int = visiblePages.indexOf(page) { if (pageIndex < firstIndex || pageIndex > lastIndex) { recycledPages.append(page) page.prepareForReuse() From 5bf71428194df4ec193bdd46e5f150f378005240 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 18:14:37 +0400 Subject: [PATCH 7/9] I fixed the bug which was when slide between images --- SKPhotoBrowser/SKPhotoBrowser.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 444e3c5..633f4f3 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -950,13 +950,13 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // for page in visiblePages { - if let pageIndex: Int = visiblePages.indexOf(page) { - if (pageIndex < firstIndex || pageIndex > lastIndex) { - recycledPages.append(page) - page.prepareForReuse() - page.removeFromSuperview() - print("Removed page at index \(pageIndex)") - } + let newPageIndex = page.tag - pageIndexTagOffset + print(newPageIndex) + if newPageIndex < firstIndex || newPageIndex > lastIndex { + recycledPages.append(page) + page.prepareForReuse() + page.removeFromSuperview() + print("Removed page at index \(newPageIndex)") } } From 2252b1409503ef932b8354cfb059a1fa63cdddfb Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 18:15:52 +0400 Subject: [PATCH 8/9] I removed prints --- SKPhotoBrowser/SKPhotoBrowser.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 633f4f3..dc85250 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -948,15 +948,12 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { lastIndex = numberOfPhotos - 1 } - // for page in visiblePages { let newPageIndex = page.tag - pageIndexTagOffset - print(newPageIndex) if newPageIndex < firstIndex || newPageIndex > lastIndex { recycledPages.append(page) page.prepareForReuse() page.removeFromSuperview() - print("Removed page at index \(newPageIndex)") } } @@ -967,8 +964,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { recycledPages.removeFirst() } - - // for var index = firstIndex; index <= lastIndex; index++ { if isDisplayingPageForIndex(index) { continue From c85abfe80244502f2591a7e353cd542642f4cf3c Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Sun, 13 Mar 2016 18:32:27 +0400 Subject: [PATCH 9/9] removed old functions --- SKPhotoBrowser/SKPhotoBrowser.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index dc85250..5f614b8 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -974,10 +974,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { page.tag = index + pageIndexTagOffset page.photo = photoAtIndex(index) - // visiblePages.insert(page) visiblePages.append(page) pagingScrollView.addSubview(page) - print("Page added at index \(index)") // if exists caption, insert if let captionView = captionViewForPhotoAtIndex(index) { captionView.frame = frameForCaptionView(captionView, index: index)