Skip to content

Commit

Permalink
Merge pull request #290 from suzuki-0000/refactor2
Browse files Browse the repository at this point in the history
pull request conflict fix
  • Loading branch information
suzuki-0000 committed Feb 13, 2018
2 parents b7f0449 + aab41ef commit 240a044
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 5.0.5
- #271 SmartInvert now works properly
- #288 Add the long photo width match screen option.
- #289 Add SWIFT_VERSION to xcconfig

## 5.0.4

#### 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.3"
s.version = "5.0.5"
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
19 changes: 13 additions & 6 deletions SKPhotoBrowser/SKAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class SKAnimator: NSObject, SKPhotoBrowserAnimatorDelegate {
let offsetY = scrollView.center.y - (scrollView.bounds.height/2)
let frame = CGRect(
x: scrollFrame.origin.x - contentOffset.x,
y: scrollFrame.origin.y + contentOffset.y + offsetY,
y: scrollFrame.origin.y + contentOffset.y + offsetY - scrollView.contentOffset.y,
width: scrollFrame.width,
height: scrollFrame.height)

resizableImageView.image = image.rotateImageByOrientation()
resizableImageView.frame = frame
resizableImageView.alpha = 1.0
Expand Down Expand Up @@ -138,10 +138,12 @@ private extension SKAnimator {
let height = width / imageRatio
let yOffset = (SKMesurement.screenHeight - height) / 2
return CGRect(x: 0, y: yOffset, width: width, height: height)
} else if SKPhotoBrowserOptions.longPhotoWidthMatchScreen && imageRatio <= 1.0 {
let height = SKMesurement.screenWidth / imageRatio
return CGRect(x: 0.0, y: 0, width: SKMesurement.screenWidth, height: height)
} else {

} else if SKPhotoBrowserOptions.longPhotoWidthMatchScreen && imageRatio <= 1.0 {
let height = SKMesurement.screenWidth / imageRatio
return CGRect(x: 0.0, y: 0, width: SKMesurement.screenWidth, height: height)

} else {
let height = SKMesurement.screenHeight
let width = height * imageRatio
let xOffset = (SKMesurement.screenWidth - width) / 2
Expand All @@ -155,6 +157,11 @@ private extension SKAnimator {
let finalFrame = self.finalImageViewFrame
browser.view.isHidden = true
browser.view.alpha = 0.0

if #available(iOS 11.0, *) {
backgroundView.accessibilityIgnoresInvertColors = true
self.resizableImageView?.accessibilityIgnoresInvertColors = true
}

UIView.animate(
withDuration: animationDuration,
Expand Down
4 changes: 4 additions & 0 deletions SKPhotoBrowser/SKPhotoBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ private extension SKPhotoBrowser {
view.backgroundColor = bgColor
view.clipsToBounds = true
view.isOpaque = false

if #available(iOS 11.0, *) {
view.accessibilityIgnoresInvertColors = true
}
}

func configurePagingScrollView() {
Expand Down
10 changes: 5 additions & 5 deletions SKPhotoBrowser/SKPhotoBrowserOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public struct SKPhotoBrowserOptions {
///
/// - 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
/// 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 SKCaptionOptions {
Expand Down
16 changes: 12 additions & 4 deletions SKPhotoBrowser/SKZoomingScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ open class SKZoomingScrollView: UIScrollView {
let deviceScreenWidth = UIScreen.main.bounds.width * scale // width in pixels. scale needs to remove if to use the old algorithm
let deviceScreenHeight = UIScreen.main.bounds.height * scale // height in pixels. scale needs to remove if to use the old algorithm

if imageView.frame.width < deviceScreenWidth {
if SKPhotoBrowserOptions.longPhotoWidthMatchScreen && imageView.frame.height >= imageView.frame.width {
minScale = 1.0
maxScale = 2.5
} else if imageView.frame.width < deviceScreenWidth {
// I think that we should to get coefficient between device screen width and image width and assign it to maxScale. I made two mode that we will get the same result for different device orientations.
if UIApplication.shared.statusBarOrientation.isPortrait {
maxScale = deviceScreenHeight / imageView.frame.width
Expand Down Expand Up @@ -155,7 +158,7 @@ open class SKZoomingScrollView: UIScrollView {
*/

// reset position
imageView.frame = CGRect(x: 0, y: 0, width: imageView.frame.size.width, height: imageView.frame.size.height)
imageView.frame.origin = CGPoint.zero
setNeedsLayout()
}

Expand Down Expand Up @@ -190,11 +193,16 @@ open class SKZoomingScrollView: UIScrollView {

var imageViewFrame: CGRect = .zero
imageViewFrame.origin = .zero
imageViewFrame.size = image.size
// long photo
if SKPhotoBrowserOptions.longPhotoWidthMatchScreen && image.size.height >= image.size.width {
let imageHeight = SKMesurement.screenWidth / image.size.width * image.size.height
imageViewFrame.size = CGSize(width: SKMesurement.screenWidth, height: imageHeight)
} else {
imageViewFrame.size = image.size
}
imageView.frame = imageViewFrame

contentSize = imageViewFrame.size

setMaxMinZoomScalesForCurrentBounds()
} else {
// change contentSize will reset contentOffset, so only set the contentsize zero when the image is nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private extension FromWebViewController {
func createWebPhotos() -> [SKPhotoProtocol] {
return (0..<10).map { (i: Int) -> SKPhotoProtocol in
// let photo = SKPhoto.photoWithImageURL("https://placehold.jp/150\(i)x150\(i).png", holder: UIImage(named: "image0.jpg")!)
let photo = SKPhoto.photoWithImageURL("https://placehold.jp/156\(i)x150\(i).png")
let photo = SKPhoto.photoWithImageURL("https://placehold.jp/10\(i)x100\(i).png")
photo.caption = caption[i%10]
photo.shouldCachePhotoURLImage = true
return photo
Expand Down

0 comments on commit 240a044

Please sign in to comment.