Skip to content

Commit

Permalink
Merge pull request #310 from suzuki-0000/v5.0.9
Browse files Browse the repository at this point in the history
v5.0.9 update
  • Loading branch information
suzuki-0000 committed Apr 23, 2018
2 parents ad40b98 + 885a5df commit 4dc3b5f
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 48 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion SKPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
87 changes: 50 additions & 37 deletions SKPhotoBrowser/SKButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,84 +23,97 @@ 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)
}

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)
}
}
6 changes: 6 additions & 0 deletions SKPhotoBrowser/SKMesurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
9 changes: 6 additions & 3 deletions SKPhotoBrowser/SKPaginationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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()
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions SKPhotoBrowser/SKPhotoBrowserOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class FromLocalViewController: UIViewController, UICollectionViewDataSource, UIC
SKPhotoBrowserOptions.displayStatusbar = true
SKPhotoBrowserOptions.displayCounterLabel = true
SKPhotoBrowserOptions.displayBackAndForwardButton = true
SKPhotoBrowserOptions.displayAction = true


setupTestData()
setupCollectionView()
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ class CustomImageCache: SKImageCacheable {

func removeImageForKey(_ key: String) {
}

func removeAllImages() {
}

}

0 comments on commit 4dc3b5f

Please sign in to comment.