From 885a5dfcfdf078d15dd76689d97ef9575122ea65 Mon Sep 17 00:00:00 2001 From: Keishi Suzuki Date: Mon, 23 Apr 2018 10:45:58 +0900 Subject: [PATCH] bug fix. --- CHANGELOG.md | 7 ++ SKPhotoBrowser.podspec | 2 +- SKPhotoBrowser/SKButtons.swift | 87 +++++++++++-------- SKPhotoBrowser/SKMesurement.swift | 6 ++ SKPhotoBrowser/SKPaginationView.swift | 9 +- SKPhotoBrowser/SKPhotoBrowserOptions.swift | 10 +-- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ .../FromLocalViewController.swift | 7 +- .../FromWebViewController.swift | 4 + 9 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 SKPhotoBrowserExample/SKPhotoBrowserExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/CHANGELOG.md b/CHANGELOG.md index 7882aee3..65975b82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 5.0.9 + +#### Updated +- #304 CaptionViewForPhotoAtIndex is not work +- #305 Padding properties for close and delete button. +- Bug At iphoneX, close / delete / pagination can be tapped correctly. + ## 5.0.8 #### Updated diff --git a/SKPhotoBrowser.podspec b/SKPhotoBrowser.podspec index 74968144..98e0cc34 100644 --- a/SKPhotoBrowser.podspec +++ b/SKPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SKPhotoBrowser" - s.version = "5.0.8" + s.version = "5.0.9" s.summary = "Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift." s.homepage = "https://github.com/suzuki-0000/SKPhotoBrowser" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/SKPhotoBrowser/SKButtons.swift b/SKPhotoBrowser/SKButtons.swift index a50a5ad8..916235af 100644 --- a/SKPhotoBrowser/SKButtons.swift +++ b/SKPhotoBrowser/SKButtons.swift @@ -23,46 +23,35 @@ class SKButton: UIButton { } } fileprivate let size: CGSize = CGSize(width: 44, height: 44) - fileprivate let buttonTopOffset: CGFloat = 30 - fileprivate var margin: CGFloat = SKPhotoBrowserOptions.closeAndDeleteButtonPadding - + fileprivate var marginX: CGFloat = 0 + fileprivate var marginY: CGFloat = 0 + fileprivate var extraMarginY: CGFloat = SKMesurement.isPhoneX ? 10 : 0 + func setup(_ imageName: String) { backgroundColor = .clear imageEdgeInsets = insets translatesAutoresizingMaskIntoConstraints = true autoresizingMask = [.flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin] - let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", - in: bundle, compatibleWith: nil) ?? UIImage() + let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", in: bundle, compatibleWith: nil) ?? UIImage() setImage(image, for: UIControlState()) } func setFrameSize(_ size: CGSize? = nil) { guard let size = size else { return } - let newRect = CGRect(x: margin, y: buttonTopOffset, width: size.width, height: size.height) + let newRect = CGRect(x: marginX, y: marginY, width: size.width, height: size.height) frame = newRect showFrame = newRect - hideFrame = CGRect(x: margin, y: -20, width: size.width, height: size.height) + hideFrame = CGRect(x: marginX, y: -marginY, width: size.width, height: size.height) } func updateFrame(_ frameSize: CGSize) { } } class SKImageButton: SKButton { - - fileprivate var leftSidePositionMargin: CGFloat { - return super.margin - } - - fileprivate var rightSidePositionMargin: CGFloat { - return SKMesurement.screenWidth - super.margin - self.size.width - } - - fileprivate var imageName: String { - return "" - } - + fileprivate var imageName: String { return "" } + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -70,37 +59,61 @@ class SKImageButton: SKButton { override init(frame: CGRect) { super.init(frame: frame) setup(imageName) - showFrame = CGRect(x: margin, y: buttonTopOffset, width: size.width, height: size.height) - hideFrame = CGRect(x: margin, y: -20, width: size.width, height: size.height) + showFrame = CGRect(x: marginX, y: marginY, width: size.width, height: size.height) + hideFrame = CGRect(x: marginX, y: -marginY, width: size.width, height: size.height) } } class SKCloseButton: SKImageButton { override var imageName: String { return "btn_common_close_wh" } - override var margin: CGFloat { + override var marginX: CGFloat { get { return SKPhotoBrowserOptions.swapCloseAndDeleteButtons - ? rightSidePositionMargin - : leftSidePositionMargin - } - set { - super.margin = newValue + ? SKMesurement.screenWidth - SKButtonOptions.closeButtonPadding.x - self.size.width + : SKButtonOptions.closeButtonPadding.x } + set { super.marginX = newValue } + } + override var marginY: CGFloat { + get { return SKButtonOptions.closeButtonPadding.y + extraMarginY } + set { super.marginY = newValue } + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override init(frame: CGRect) { + super.init(frame: frame) + setup(imageName) + showFrame = CGRect(x: marginX, y: marginY, width: size.width, height: size.height) + hideFrame = CGRect(x: marginX, y: -marginY, width: size.width, height: size.height) } } class SKDeleteButton: SKImageButton { override var imageName: String { return "btn_common_delete_wh" } - override var margin: CGFloat { - get { return SKPhotoBrowserOptions.swapCloseAndDeleteButtons - ? leftSidePositionMargin - : rightSidePositionMargin + override var marginX: CGFloat { + get { + return SKPhotoBrowserOptions.swapCloseAndDeleteButtons + ? SKMesurement.screenWidth - SKButtonOptions.deleteButtonPadding.x - self.size.width + : SKButtonOptions.deleteButtonPadding.x } - set { super.margin = newValue } + set { super.marginX = newValue } } - - override func updateFrame(_ newScreenSize: CGSize) { - showFrame = CGRect(x: newScreenSize.width - size.width, y: buttonTopOffset, width: size.width, height: size.height) - hideFrame = CGRect(x: newScreenSize.width - size.width, y: -20, width: size.width, height: size.height) + override var marginY: CGFloat { + get { return SKButtonOptions.deleteButtonPadding.y + extraMarginY } + set { super.marginY = newValue } + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override init(frame: CGRect) { + super.init(frame: frame) + setup(imageName) + showFrame = CGRect(x: marginX, y: marginY, width: size.width, height: size.height) + hideFrame = CGRect(x: marginX, y: -marginY, width: size.width, height: size.height) } } diff --git a/SKPhotoBrowser/SKMesurement.swift b/SKPhotoBrowser/SKMesurement.swift index bcb772c2..94f43ae7 100644 --- a/SKPhotoBrowser/SKMesurement.swift +++ b/SKPhotoBrowser/SKMesurement.swift @@ -27,4 +27,10 @@ struct SKMesurement { static var screenRatio: CGFloat { return screenWidth / screenHeight } + static var isPhoneX: Bool { + if isPhone && UIScreen.main.nativeBounds.height == 2436 { + return true + } + return false + } } diff --git a/SKPhotoBrowser/SKPaginationView.swift b/SKPhotoBrowser/SKPaginationView.swift index fe377526..5a70fefe 100644 --- a/SKPhotoBrowser/SKPaginationView.swift +++ b/SKPhotoBrowser/SKPaginationView.swift @@ -14,6 +14,8 @@ class SKPaginationView: UIView { var counterLabel: UILabel? var prevButton: UIButton? var nextButton: UIButton? + private var margin: CGFloat = 100 + private var extraMargin: CGFloat = SKMesurement.isPhoneX ? 40 : 0 fileprivate weak var browser: SKPhotoBrowser? @@ -26,9 +28,10 @@ class SKPaginationView: UIView { } convenience init(frame: CGRect, browser: SKPhotoBrowser?) { - self.init(frame: CGRect(x: 0, y: frame.height - 100, width: frame.width, height: 100)) + self.init(frame: frame) + self.frame = CGRect(x: 0, y: frame.height - margin - extraMargin, width: frame.width, height: 100) self.browser = browser - + setupApperance() setupCounterLabel() setupPrevButton() @@ -52,7 +55,7 @@ class SKPaginationView: UIView { } func updateFrame(frame: CGRect) { - self.frame = CGRect(x: 0, y: frame.height - 100, width: frame.width, height: 100) + self.frame = CGRect(x: 0, y: frame.height - margin - extraMargin, width: frame.width, height: 100) } func update(_ currentPageIndex: Int) { diff --git a/SKPhotoBrowser/SKPhotoBrowserOptions.swift b/SKPhotoBrowser/SKPhotoBrowserOptions.swift index 5d23705d..db6348ac 100644 --- a/SKPhotoBrowser/SKPhotoBrowserOptions.swift +++ b/SKPhotoBrowser/SKPhotoBrowserOptions.swift @@ -40,17 +40,17 @@ public struct SKPhotoBrowserOptions { public static var swapCloseAndDeleteButtons: Bool = false public static var disableVerticalSwipe: Bool = false - /// Offset from top and from nearest screen edge of close button and delete button. - /// - /// - Default: 5 - public static var closeAndDeleteButtonPadding: CGFloat = 5 - /// if this value is true, the long photo width will match the screen, /// and the minScale is 1.0, the maxScale is 2.5 /// Default: false public static var longPhotoWidthMatchScreen: Bool = false } +public struct SKButtonOptions { + public static var closeButtonPadding: CGPoint = CGPoint(x: 5, y: 20) + public static var deleteButtonPadding: CGPoint = CGPoint(x: 5, y: 20) +} + public struct SKCaptionOptions { public static var textColor: UIColor = .white public static var textAlignment: NSTextAlignment = .center diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample/FromLocalViewController.swift b/SKPhotoBrowserExample/SKPhotoBrowserExample/FromLocalViewController.swift index bf04fe25..a57d362a 100644 --- a/SKPhotoBrowserExample/SKPhotoBrowserExample/FromLocalViewController.swift +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample/FromLocalViewController.swift @@ -22,8 +22,7 @@ class FromLocalViewController: UIViewController, UICollectionViewDataSource, UIC SKPhotoBrowserOptions.displayStatusbar = true SKPhotoBrowserOptions.displayCounterLabel = true SKPhotoBrowserOptions.displayBackAndForwardButton = true - SKPhotoBrowserOptions.displayAction = true - + setupTestData() setupCollectionView() } @@ -106,6 +105,10 @@ extension FromLocalViewController { func viewForPhoto(_ browser: SKPhotoBrowser, index: Int) -> UIView? { return collectionView.cellForItem(at: IndexPath(item: index, section: 0)) } + + func captionViewForPhotoAtIndex(index: Int) -> SKCaptionView? { + return nil + } } // MARK: - private diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample/FromWebViewController.swift b/SKPhotoBrowserExample/SKPhotoBrowserExample/FromWebViewController.swift index 14754ed2..34d6a99b 100644 --- a/SKPhotoBrowserExample/SKPhotoBrowserExample/FromWebViewController.swift +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample/FromWebViewController.swift @@ -83,4 +83,8 @@ class CustomImageCache: SKImageCacheable { func removeImageForKey(_ key: String) { } + + func removeAllImages() { + } + }