Compare commits

...

6 Commits

Author SHA1 Message Date
Grigory Ulanov e87ec9eb72 black color 2016-10-11 11:53:12 +03:00
Grigory Ulanov 2db02eecc0 text color changed 2016-10-11 11:15:08 +03:00
Grigory Ulanov d40c5d2c2e navigationBar added 2016-10-10 16:47:04 +03:00
Grigory Ulanov 5714a95908 full view controller swipe fade 2016-09-21 16:29:37 +03:00
keishi suzuki 8d2c1f3b38 Merge pull request #146 from suzuki-0000/bugfix/#145
fixed scrolling performance, result of adding padding to the displaye…
2016-09-16 11:06:54 +09:00
suzuki_keishi 464114e40d fixed scrolling performance, result of adding padding to the displayed image. 2016-09-16 11:06:06 +09:00
8 changed files with 117 additions and 19 deletions

View File

@ -1,5 +1,12 @@
# Change Log
## 3.1.2
Released on 16-9-2016
#### Fixed
- Scrolling performance slowed #145
## 3.1.1
Released on 15-9-2016

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SKPhotoBrowser"
s.version = "3.1.1"
s.version = "3.1.2"
s.summary = "Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift2.0."
s.homepage = "https://github.com/suzuki-0000/SKPhotoBrowser"
s.license = { :type => "MIT", :file => "LICENSE" }

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
0AE527521DABB87500619FAD /* SKNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE527511DABB87500619FAD /* SKNavigationBar.swift */; };
210E53ED1C986D3A008DD5E3 /* UIView+Radius.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210E53EC1C986D3A008DD5E3 /* UIView+Radius.swift */; };
210E53EF1C986D57008DD5E3 /* UIImage+Rotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210E53EE1C986D57008DD5E3 /* UIImage+Rotation.swift */; };
26C97AD51D0EB6870039F6CB /* SKCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26C97AD41D0EB6870039F6CB /* SKCache.swift */; };
@ -44,6 +45,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
0AE527511DABB87500619FAD /* SKNavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKNavigationBar.swift; sourceTree = "<group>"; };
210E53EC1C986D3A008DD5E3 /* UIView+Radius.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+Radius.swift"; path = "extensions/UIView+Radius.swift"; sourceTree = "<group>"; };
210E53EE1C986D57008DD5E3 /* UIImage+Rotation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImage+Rotation.swift"; path = "extensions/UIImage+Rotation.swift"; sourceTree = "<group>"; };
26C97AD41D0EB6870039F6CB /* SKCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKCache.swift; sourceTree = "<group>"; };
@ -136,6 +138,7 @@
8909B5411BC791510060A053 /* SKPhotoBrowser.swift */,
89C24A811D657AD1005F09A9 /* SKPhotoBrowserOptions.swift */,
890A6F1F1D5D9E53003B01F0 /* SKToolbar.swift */,
0AE527511DABB87500619FAD /* SKNavigationBar.swift */,
8909B5331BC791280060A053 /* SKPhotoBrowser.h */,
8917B1AF1D5A13DE000CE1C4 /* SKPhotoBrowserDelegate.swift */,
89D0BA481D59966B002A811B /* SKMesurement.swift */,
@ -300,6 +303,7 @@
8917B1B41D5A14B0000CE1C4 /* SKButtons.swift in Sources */,
89C24A821D657AD1005F09A9 /* SKPhotoBrowserOptions.swift in Sources */,
26C97AD51D0EB6870039F6CB /* SKCache.swift in Sources */,
0AE527521DABB87500619FAD /* SKNavigationBar.swift in Sources */,
210E53EF1C986D57008DD5E3 /* UIImage+Rotation.swift in Sources */,
8909B5431BC791510060A053 /* SKCaptionView.swift in Sources */,
8909B5491BC791510060A053 /* SKPhotoBrowser.swift in Sources */,

View File

@ -0,0 +1,55 @@
//
// SKNavigationBar.swift
// SKPhotoBrowser
//
// Created by Григорий Уланов on 10.10.16.
// Copyright © 2016 suzuki_keishi. All rights reserved.
//
import UIKit
class SKNavigationBar: UINavigationBar {
var showFrame: CGRect!
var hideFrame: CGRect!
private static let toolBarHeight: CGFloat = 64.0
private weak var browser: SKPhotoBrowser?
convenience init(browser: SKPhotoBrowser) {
self.init(frame: CGRect.zero)
self.browser = browser
translucent = false
tintColor = UIColor.whiteColor()
barTintColor = UIColor.blackColor()
titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
let navigationItem = UINavigationItem()
pushNavigationItem(navigationItem, animated: false)
}
func updateNavigationBar(currentPageIndex: Int) {
guard let browser = browser else { return }
if browser.numberOfPhotos > 1 {
self.topItem?.title = "\(currentPageIndex + 1) \(SKPhotoBrowserOptions.navigationBarCounterSepatator) \(browser.numberOfPhotos)"
} else {
self.topItem?.title = nil
}
}
func setNewFrame(rect: CGRect) {
self.frame = rect
showFrame = rect
hideFrame = CGRect(x: rect.origin.x, y: rect.origin.y - 20, width: rect.size.width, height: rect.size.height)
}
func updateFrame(parentSize: CGSize) {
let newRect = CGRect(x: 0, y: 0, width: parentSize.width, height: SKNavigationBar.toolBarHeight)
setNewFrame(newRect)
}
}

View File

@ -18,6 +18,8 @@ public class SKPhotoBrowser: UIViewController {
private var closeButton: SKCloseButton!
private var deleteButton: SKDeleteButton!
private var toolbar: SKToolbar!
private var navigationBar: SKNavigationBar!
// actions
private var activityViewController: UIActivityViewController!
@ -42,6 +44,10 @@ public class SKPhotoBrowser: UIViewController {
// timer
private var controlVisibilityTimer: NSTimer!
// blocks
public var willDismissPage: (() -> Void)?
public var didPresentPage: (() -> Void)?
// delegate
private let animator = SKAnimator()
@ -112,11 +118,12 @@ public class SKPhotoBrowser: UIViewController {
configureAppearance()
configureCloseButton()
configureDeleteButton()
configureNavigationBar()
configureToolbar()
animator.willPresent(self)
didPresentPage?()
}
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
@ -135,6 +142,7 @@ public class SKPhotoBrowser: UIViewController {
closeButton.updateFrame()
deleteButton.updateFrame()
navigationBar.updateFrame(view.bounds.size)
pagingScrollView.updateFrame(view.bounds, currentPageIndex: currentPageIndex)
toolbar.frame = frameForToolbarAtOrientation()
@ -184,6 +192,7 @@ public class SKPhotoBrowser: UIViewController {
isPerformingLayout = true
toolbar.updateToolbar(currentPageIndex)
navigationBar.updateNavigationBar(currentPageIndex)
// reset local cache
pagingScrollView.reload()
@ -220,6 +229,7 @@ public class SKPhotoBrowser: UIViewController {
public func determineAndClose() {
delegate?.willDismissAtPageIndex?(currentPageIndex)
animator.willDismiss(self)
willDismissPage?()
}
}
@ -276,6 +286,7 @@ public extension SKPhotoBrowser {
}
isEndAnimationByToolBar = false
toolbar.updateToolbar(currentPageIndex)
navigationBar.updateNavigationBar(currentPageIndex)
let pageFrame = frameForPageAtIndex(index)
pagingScrollView.animate(pageFrame)
@ -445,7 +456,7 @@ internal extension SKPhotoBrowser {
? zoomingScrollView.center.y - viewHalfHeight
: -(zoomingScrollView.center.y - viewHalfHeight)) / viewHalfHeight
view.backgroundColor = SKPhotoBrowserOptions.backgroundColor.colorWithAlphaComponent(max(0.7, offset))
view.alpha = max(0.7, offset)
// gesture end
if sender.state == .Ended {
@ -470,6 +481,7 @@ internal extension SKPhotoBrowser {
UIView.setAnimationDuration(animationDuration)
UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn)
view.backgroundColor = SKPhotoBrowserOptions.backgroundColor
view.alpha = 1
zoomingScrollView.center = CGPoint(x: finalX, y: finalY)
UIView.commitAnimations()
}
@ -559,6 +571,13 @@ private extension SKPhotoBrowser {
deleteButton.hidden = !SKPhotoBrowserOptions.displayDeleteButton
view.addSubview(deleteButton)
}
func configureNavigationBar() {
navigationBar = SKNavigationBar(browser: self)
navigationBar.updateFrame(view.bounds.size)
navigationBar.hidden = !SKPhotoBrowserOptions.displayNavigationBar
view.addSubview(navigationBar)
}
func configureToolbar() {
toolbar = SKToolbar(frame: frameForToolbarAtOrientation(), browser: self)
@ -584,6 +603,10 @@ private extension SKPhotoBrowser {
self.deleteButton.alpha = alpha
self.deleteButton.frame = hidden ? self.deleteButton.hideFrame : self.deleteButton.showFrame
}
if SKPhotoBrowserOptions.displayNavigationBar {
self.navigationBar.alpha = alpha
self.navigationBar.frame = hidden ? self.navigationBar.hideFrame : self.navigationBar.showFrame
}
captionViews.forEach { $0.alpha = alpha }
},
completion: nil)
@ -607,6 +630,7 @@ private extension SKPhotoBrowser {
gotoPreviousPage()
}
toolbar.updateToolbar(currentPageIndex)
navigationBar.updateNavigationBar(currentPageIndex)
} else if photos.count == 1 {
dismissPhotoBrowser(animated: false)
@ -636,6 +660,7 @@ extension SKPhotoBrowser: UIScrollViewDelegate {
if currentPageIndex != previousCurrentPage {
delegate?.didShowPhotoAtIndex?(currentPageIndex)
toolbar.updateToolbar(currentPageIndex)
navigationBar.updateNavigationBar(currentPageIndex)
}
}

View File

@ -71,5 +71,6 @@ import Foundation
- Returns: the view to animate to
*/
optional func viewForPhoto(browser: SKPhotoBrowser, index: Int) -> UIView?
}

View File

@ -21,6 +21,7 @@ public struct SKPhotoBrowserOptions {
public static var disableVerticalSwipe: Bool = false
public static var displayCloseButton: Bool = true
public static var displayNavigationBar: Bool = true
public static var displayDeleteButton: Bool = false
public static var displayHorizontalScrollIndicator: Bool = true
@ -30,13 +31,16 @@ public struct SKPhotoBrowserOptions {
public static var enableZoomBlackArea: Bool = true
public static var enableSingleTapDismiss: Bool = false
public static var imagePaddingX: CGFloat = 0
public static var imagePaddingY: CGFloat = 0
public static var backgroundColor = UIColor.blackColor()
public static var textAndIconColor = UIColor.whiteColor()
public static var toolbarTextShadowColor = UIColor.darkTextColor()
public static var navigationBarCounterSepatator: String = "из"
public static var toolbarFont = UIFont(name: "Helvetica", size: 16.0)
public static var captionFont = UIFont.systemFontOfSize(17.0)
}
// FIXED: Scrolling performance slowed #145
// public static var imagePaddingX: CGFloat = 0
// public static var imagePaddingY: CGFloat = 0
}

View File

@ -183,20 +183,22 @@ public class SKZoomingScrollView: UIScrollView {
if let image = photo.underlyingImage {
// FIXED: Scrolling performance slowed #145
// create padding
let width: CGFloat = image.size.width + SKPhotoBrowserOptions.imagePaddingX
let height: CGFloat = image.size.height + SKPhotoBrowserOptions.imagePaddingY;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), false, 0.0);
let context: CGContextRef = UIGraphicsGetCurrentContext()!;
UIGraphicsPushContext(context);
let origin: CGPoint = CGPointMake((width - image.size.width) / 2, (height - image.size.height) / 2);
image.drawAtPoint(origin)
UIGraphicsPopContext();
let imageWithPadding = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// let width: CGFloat = image.size.width + SKPhotoBrowserOptions.imagePaddingX
// let height: CGFloat = image.size.height + SKPhotoBrowserOptions.imagePaddingY;
// UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), false, 0.0);
// let context: CGContextRef = UIGraphicsGetCurrentContext()!;
// UIGraphicsPushContext(context);
// let origin: CGPoint = CGPointMake((width - image.size.width) / 2, (height - image.size.height) / 2);
// image.drawAtPoint(origin)
// UIGraphicsPopContext();
// let imageWithPadding = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
// image
photoImageView.image = imageWithPadding
photoImageView.image = image
photoImageView.contentMode = photo.contentMode
photoImageView.backgroundColor = SKPhotoBrowserOptions.backgroundColor
@ -336,4 +338,4 @@ private extension SKZoomingScrollView {
return CGRect(x: x, y: y, width: w, height: h)
}
}
}