Merge pull request #48 from alexsanderskywork/master
fixed the bug which was when slide between images
This commit is contained in:
commit
91ebfcb186
|
|
@ -100,6 +100,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
// photo's paging
|
||||
private var visiblePages = [SKZoomingScrollView]()//: Set<SKZoomingScrollView> = Set()
|
||||
private var recycledPages = [SKZoomingScrollView]()
|
||||
|
||||
private var initialPageIndex: Int = 0
|
||||
private var currentPageIndex: Int = 0
|
||||
|
||||
|
|
@ -116,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
|
||||
|
|
@ -245,7 +246,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
toolCounterButton = UIBarButtonItem(customView: toolCounterLabel)
|
||||
|
||||
// starting setting
|
||||
setStartupValue()
|
||||
setCustomSetting()
|
||||
setSettingCloseButton()
|
||||
setSettingDeleteButton()
|
||||
|
|
@ -325,11 +325,13 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - set startap values
|
||||
private func setStartupValue() {
|
||||
startOrientation = UIApplication.sharedApplication().statusBarOrientation.rawValue
|
||||
public override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
recycledPages.removeAll()
|
||||
}
|
||||
|
||||
// MARK: - set startap values
|
||||
|
||||
// MARK: - setting of buttons
|
||||
// This function should be at the beginning of the other functions
|
||||
private func setCustomSetting() {
|
||||
|
|
@ -512,6 +514,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
// reset local cache
|
||||
visiblePages.removeAll()
|
||||
recycledPages.removeAll()
|
||||
|
||||
// set content offset
|
||||
pagingScrollView.contentOffset = contentOffsetForPageAtIndex(currentPageIndex)
|
||||
|
|
@ -895,7 +898,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
if isViewLoaded() {
|
||||
jumpToPageAtIndex(index)
|
||||
if isViewActive {
|
||||
if !isViewActive {
|
||||
tilePages()
|
||||
}
|
||||
}
|
||||
|
|
@ -945,6 +948,22 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
lastIndex = numberOfPhotos - 1
|
||||
}
|
||||
|
||||
for page in visiblePages {
|
||||
let newPageIndex = page.tag - pageIndexTagOffset
|
||||
if newPageIndex < firstIndex || newPageIndex > lastIndex {
|
||||
recycledPages.append(page)
|
||||
page.prepareForReuse()
|
||||
page.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -955,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)
|
||||
|
||||
// if exists caption, insert
|
||||
if let captionView = captionViewForPhotoAtIndex(index) {
|
||||
captionView.frame = frameForCaptionView(captionView, index: index)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin
|
|||
var photo: SKPhotoProtocol! {
|
||||
didSet {
|
||||
photoImageView.image = nil
|
||||
displayImage()
|
||||
if photo != nil {
|
||||
displayImage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,6 +148,10 @@ public class SKZoomingScrollView: UIScrollView, UIScrollViewDelegate, SKDetectin
|
|||
|
||||
public func prepareForReuse() {
|
||||
photo = nil
|
||||
if captionView != nil {
|
||||
captionView.removeFromSuperview()
|
||||
captionView = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - image
|
||||
|
|
|
|||
|
|
@ -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 = "<group>"; };
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue