Skip to content

Commit

Permalink
Merge branch 'master' of github.com:suzuki-0000/SKPhotoBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-0000 committed Sep 14, 2018
2 parents c97b23b + b8fd019 commit 65ab36a
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 48 deletions.
14 changes: 9 additions & 5 deletions SKPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = suzuki_keishi;
TargetAttributes = {
8909B52F1BC791280060A053 = {
Expand Down Expand Up @@ -351,12 +351,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -407,12 +409,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -462,8 +466,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -483,8 +487,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.SKPhotoBrowser;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Release;
};
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
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
22 changes: 13 additions & 9 deletions SKPhotoBrowser/SKActionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ extension SKActionView {
addSubview(closeButton)
}

guard let size = size else { return }
closeButton.setFrameSize(size)
if let size = size {
closeButton.setFrameSize(size)
}

guard let image = image else { return }
closeButton.setImage(image, for: UIControlState())
if let image = image {
closeButton.setImage(image, for: for: .normal)
}
}

func configureDeleteButton(image: UIImage? = nil, size: CGSize? = nil) {
Expand All @@ -109,11 +111,13 @@ extension SKActionView {
deleteButton.isHidden = !SKPhotoBrowserOptions.displayDeleteButton
addSubview(deleteButton)
}

guard let size = size else { return }
deleteButton.setFrameSize(size)

guard let image = image else { return }
deleteButton.setImage(image, for: UIControlState())
if let size = size {
deleteButton.setFrameSize(size)
}

if let image = image {
deleteButton.setImage(image, for: .normal)
}
}
}
11 changes: 7 additions & 4 deletions SKPhotoBrowser/SKAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SKAnimator: NSObject, SKPhotoBrowserAnimatorDelegate {
guard let window = UIApplication.shared.preferredApplicationWindow else { fatalError() }

let backgroundView = UIView(frame: window.frame)
backgroundView.backgroundColor = .black
backgroundView.backgroundColor = SKPhotoBrowserOptions.backgroundColor
backgroundView.alpha = 0.0
return backgroundView
}()
Expand Down Expand Up @@ -84,7 +84,10 @@ class SKAnimator: NSObject, SKPhotoBrowserAnimatorDelegate {
let scrollView = browser.pageDisplayedAtIndex(browser.currentPageIndex) else {

senderViewForAnimation?.isHidden = false
browser.dismissPhotoBrowser(animated: false)
browser.dismissPhotoBrowser(animated: false) {
self.resizableImageView?.removeFromSuperview()
self.backgroundView.removeFromSuperview()
}
return
}

Expand Down Expand Up @@ -170,7 +173,7 @@ private extension SKAnimator {
delay: 0,
usingSpringWithDamping: animationDamping,
initialSpringVelocity: 0,
options: UIViewAnimationOptions(),
options: UIView.AnimationOptions(),
animations: {
browser.showButtons()
self.backgroundView.alpha = 1.0
Expand All @@ -192,7 +195,7 @@ private extension SKAnimator {
delay: 0,
usingSpringWithDamping: animationDamping,
initialSpringVelocity: 0,
options: UIViewAnimationOptions(),
options: UIView.AnimationOptions(),
animations: {
self.backgroundView.alpha = 0.0
self.resizableImageView?.layer.frame = finalFrame
Expand Down
2 changes: 1 addition & 1 deletion SKPhotoBrowser/SKButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SKButton: UIButton {
autoresizingMask = [.flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin]

let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", in: bundle, compatibleWith: nil) ?? UIImage()
setImage(image, for: UIControlState())
setImage(image, for: .normal)
}

func setFrameSize(_ size: CGSize? = nil) {
Expand Down
2 changes: 1 addition & 1 deletion SKPhotoBrowser/SKCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

open class SKCache {
open static let sharedCache = SKCache()
public static let sharedCache = SKCache()
open var imageCache: SKCacheable

init() {
Expand Down
8 changes: 4 additions & 4 deletions SKPhotoBrowser/SKCaptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ open class SKCaptionView: UIView {
}

public convenience init(photo: SKPhotoProtocol) {
let screenBound = UIScreen.main.bounds
self.init(frame: CGRect(x: 0, y: 0, width: screenBound.size.width, height: screenBound.size.height))
self.init(frame: CGRect(x: 0, y: 0, width: SKMesurement.screenWidth, height: SKMesurement.screenHeight))
self.photo = photo
setup()
}
Expand All @@ -37,7 +36,7 @@ open class SKCaptionView: UIView {
let width: CGFloat = size.width - photoLabelPadding * 2
let height: CGFloat = photoLabel.font.lineHeight * CGFloat(photoLabel.numberOfLines)

let attributedText = NSAttributedString(string: text, attributes: [NSAttributedStringKey.font: font])
let attributedText = NSAttributedString(string: text, attributes: [NSAttributedString.Key.font: font])
let textSize = attributedText.boundingRect(with: CGSize(width: width, height: height), options: .usesLineFragmentOrigin, context: nil).size

return CGSize(width: textSize.width, height: textSize.height + photoLabelPadding * 2)
Expand All @@ -57,7 +56,7 @@ private extension SKCaptionView {
photoLabel = UILabel(frame: CGRect(x: photoLabelPadding, y: 0, width: bounds.size.width - (photoLabelPadding * 2), height: bounds.size.height))
photoLabel.autoresizingMask = [.flexibleWidth, .flexibleHeight]
photoLabel.isOpaque = false
photoLabel.backgroundColor = .clear
photoLabel.backgroundColor = SKCaptionOptions.backgroundColor
photoLabel.textColor = SKCaptionOptions.textColor
photoLabel.textAlignment = SKCaptionOptions.textAlignment
photoLabel.lineBreakMode = SKCaptionOptions.lineBreakMode
Expand All @@ -66,6 +65,7 @@ private extension SKCaptionView {
photoLabel.shadowColor = UIColor(white: 0.0, alpha: 0.5)
photoLabel.shadowOffset = CGSize(width: 0.0, height: 1.0)
photoLabel.text = photo?.caption

addSubview(photoLabel)
}
}
Expand Down
2 changes: 1 addition & 1 deletion SKPhotoBrowser/SKIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SKIndicatorView: UIActivityIndicatorView {
override init(frame: CGRect) {
super.init(frame: frame)
center = CGPoint(x: frame.width / 2, y: frame.height / 2)
activityIndicatorViewStyle = SKPhotoBrowserOptions.indicatorStyle
style = SKPhotoBrowserOptions.indicatorStyle
color = SKPhotoBrowserOptions.indicatorColor
}
}
2 changes: 1 addition & 1 deletion SKPhotoBrowser/SKLocalPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open class SKLocalPhoto: NSObject, SKPhotoProtocol {

open var underlyingImage: UIImage!
open var photoURL: String!
open var contentMode: UIViewContentMode = .scaleToFill
open var contentMode: UIView.ContentMode = .scaleToFill
open var shouldCachePhotoURLImage: Bool = false
open var caption: String?
open var index: Int = 0
Expand Down
4 changes: 2 additions & 2 deletions SKPhotoBrowser/SKMesurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct SKMesurement {
return UIApplication.shared.statusBarFrame.height
}
static var screenHeight: CGFloat {
return UIScreen.main.bounds.height
return UIApplication.shared.preferredApplicationWindow?.bounds.height ?? UIScreen.main.bounds.height
}
static var screenWidth: CGFloat {
return UIScreen.main.bounds.width
return UIApplication.shared.preferredApplicationWindow?.bounds.width ?? UIScreen.main.bounds.width
}
static var screenScale: CGFloat {
return UIScreen.main.scale
Expand Down
4 changes: 2 additions & 2 deletions SKPhotoBrowser/SKPaginationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SKPaginationView: UIView {
}

func updateFrame(frame: CGRect) {
self.frame = CGRect(x: 0, y: frame.height - margin - extraMargin, width: frame.width, height: 100)
self.frame = CGRect(x: 0, y: frame.height - margin, width: frame.width, height: 100)
}

func update(_ currentPageIndex: Int) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class SKPaginationButton: UIButton {

let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)",
in: bundle, compatibleWith: nil) ?? UIImage()
setImage(image, for: UIControlState())
setImage(image, for: .normal)
}
}

Expand Down
12 changes: 11 additions & 1 deletion SKPhotoBrowser/SKPagingScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SKPagingScrollView: UIScrollView {
visiblePages.removeAll()
recycledPages.removeAll()
}


func loadAdjacentPhotosIfNecessary(_ photo: SKPhotoProtocol, currentPageIndex: Int) {
guard let browser = browser, let page = pageDisplayingAtPhoto(photo) else {
Expand Down Expand Up @@ -162,9 +163,18 @@ class SKPagingScrollView: UIScrollView {
let pageFrame = frameForPageAtIndex(index)
let captionSize = captionView.sizeThatFits(CGSize(width: pageFrame.size.width, height: 0))
let paginationFrame = browser?.paginationView.frame ?? .zero
let toolbarFrame = browser?.toolbar.frame ?? .zero

var frameSet = CGRect.zero
switch SKCaptionOptions.captionLocation {
case .basic:
frameSet = paginationFrame
case .bottom:
frameSet = toolbarFrame
}

return CGRect(x: pageFrame.origin.x,
y: paginationFrame.minY - captionSize.height,
y: pageFrame.size.height - captionSize.height - frameSet.height,
width: pageFrame.size.width, height: captionSize.height)
}

Expand Down
4 changes: 2 additions & 2 deletions SKPhotoBrowser/SKPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
var index: Int { get set }
var underlyingImage: UIImage! { get }
var caption: String? { get }
var contentMode: UIViewContentMode { get set }
var contentMode: UIView.ContentMode { get set }
func loadUnderlyingImageAndNotify()
func checkCache()
}
Expand All @@ -22,7 +22,7 @@ open class SKPhoto: NSObject, SKPhotoProtocol {
open var index: Int = 0
open var underlyingImage: UIImage!
open var caption: String?
open var contentMode: UIViewContentMode = .scaleAspectFill
open var contentMode: UIView.ContentMode = .scaleAspectFill
open var shouldCachePhotoURLImage: Bool = false
open var photoURL: String!

Expand Down
17 changes: 14 additions & 3 deletions SKPhotoBrowser/SKPhotoBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open class SKPhotoBrowser: UIViewController {

fileprivate var actionView: SKActionView!
fileprivate(set) var paginationView: SKPaginationView!
fileprivate var toolbar: SKToolbar!
var toolbar: SKToolbar!

// actions
fileprivate var activityViewController: UIActivityViewController!
Expand Down Expand Up @@ -137,7 +137,12 @@ open class SKPhotoBrowser: UIViewController {
actionView.updateFrame(frame: view.frame)

// paging
paginationView.updateFrame(frame: view.frame)
switch SKCaptionOptions.captionLocation {
case .basic:
paginationView.updateFrame(frame: view.frame)
case .bottom:
paginationView.frame = frameForPaginationAtOrientation()
}
pagingScrollView.updateFrame(view.bounds, currentPageIndex: currentPageIndex)

isPerformingLayout = false
Expand Down Expand Up @@ -394,6 +399,12 @@ internal extension SKPhotoBrowser {
return view.bounds.divided(atDistance: 44, from: .maxYEdge).slice.offsetBy(dx: 0, dy: 44)
}

func frameForPaginationAtOrientation() -> CGRect {
let offset = UIInterfaceOrientationIsLandscape(UIApplication.shared.statusBarOrientation) ? 35 : 44

return CGRect(x: 0, y: self.view.bounds.size.height - CGFloat(offset), width: self.view.bounds.size.width, height: CGFloat(offset))
}

func frameForPageAtIndex(_ index: Int) -> CGRect {
let bounds = pagingScrollView.bounds
var pageFrame = bounds
Expand Down Expand Up @@ -456,7 +467,7 @@ internal extension SKPhotoBrowser {

UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(animationDuration)
UIView.setAnimationCurve(UIViewAnimationCurve.easeIn)
UIView.setAnimationCurve(UIView.AnimationCurve.easeIn)
zoomingScrollView.center = CGPoint(x: finalX, y: finalY)
UIView.commitAnimations()
}
Expand Down
9 changes: 8 additions & 1 deletion SKPhotoBrowser/SKPhotoBrowserOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct SKPhotoBrowserOptions {

public static var backgroundColor: UIColor = .black
public static var indicatorColor: UIColor = .white
public static var indicatorStyle: UIActivityIndicatorViewStyle = .whiteLarge
public static var indicatorStyle: UIActivityIndicatorView.Style = .whiteLarge

/// By default close button is on left side and delete button is on right.
///
Expand All @@ -55,11 +55,18 @@ public struct SKButtonOptions {
}

public struct SKCaptionOptions {
public enum CaptionLocation {
case basic
case bottom
}

public static var textColor: UIColor = .white
public static var textAlignment: NSTextAlignment = .center
public static var numberOfLine: Int = 3
public static var lineBreakMode: NSLineBreakMode = .byTruncatingTail
public static var font: UIFont = .systemFont(ofSize: 17.0)
public static var backgroundColor: UIColor = .clear
public static var captionLocation: CaptionLocation = .basic
}

public struct SKToolbarOptions {
Expand Down
Loading

0 comments on commit 65ab36a

Please sign in to comment.