Merge branch 'master' of github.com:krummler/SKPhotoBrowser into cameraroll
# Conflicts: # SKPhotoBrowser/SKPhotoBrowser.swift
This commit is contained in:
commit
23677c500a
|
|
@ -87,9 +87,10 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
}
|
||||
|
||||
// device property
|
||||
final let screenBound = UIScreen.mainScreen().bounds
|
||||
var screenWidth: CGFloat { return screenBound.size.width }
|
||||
var screenHeight: CGFloat { return screenBound.size.height }
|
||||
final let screenBounds = UIScreen.mainScreen().bounds
|
||||
var screenWidth: CGFloat { return screenBounds.size.width }
|
||||
var screenHeight: CGFloat { return screenBounds.size.height }
|
||||
var screenRatio: CGFloat { return screenWidth / screenHeight }
|
||||
|
||||
// custom abilities
|
||||
public var displayAction: Bool = true
|
||||
|
|
@ -115,6 +116,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
// tool for controls
|
||||
private var applicationWindow: UIWindow!
|
||||
private var backgroundView: UIView!
|
||||
private var toolBar: UIToolbar!
|
||||
private var toolCounterLabel: UILabel!
|
||||
private var toolCounterButton: UIBarButtonItem!
|
||||
|
|
@ -244,6 +246,12 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
view.backgroundColor = UIColor.blackColor()
|
||||
view.clipsToBounds = true
|
||||
view.opaque = false
|
||||
|
||||
backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
|
||||
backgroundView.backgroundColor = .blackColor()
|
||||
backgroundView.alpha = 0.0
|
||||
applicationWindow.addSubview(backgroundView)
|
||||
|
||||
// setup paging
|
||||
let pagingScrollViewFrame = frameForPagingScrollView()
|
||||
|
|
@ -252,7 +260,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
pagingScrollView.delegate = self
|
||||
pagingScrollView.showsHorizontalScrollIndicator = true
|
||||
pagingScrollView.showsVerticalScrollIndicator = true
|
||||
pagingScrollView.backgroundColor = UIColor.blackColor()
|
||||
pagingScrollView.backgroundColor = UIColor.clearColor()
|
||||
pagingScrollView.contentSize = contentSizeForPagingScrollView()
|
||||
view.addSubview(pagingScrollView)
|
||||
|
||||
|
|
@ -694,6 +702,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
// MARK: - panGestureRecognized
|
||||
public func panGestureRecognized(sender: UIPanGestureRecognizer) {
|
||||
|
||||
backgroundView.hidden = true
|
||||
let scrollView = pageDisplayedAtIndex(currentPageIndex)
|
||||
|
||||
let viewHeight = scrollView.frame.size.height
|
||||
|
|
@ -715,12 +724,15 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
translatedPoint = CGPoint(x: firstX, y: firstY + translatedPoint.y)
|
||||
scrollView.center = translatedPoint
|
||||
|
||||
view.opaque = true
|
||||
let minOffset = viewHalfHeight/4
|
||||
let offset = 1 - (scrollView.center.y > viewHalfHeight ? scrollView.center.y - viewHalfHeight : -(scrollView.center.y - viewHalfHeight)) / viewHalfHeight
|
||||
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(max(0.7, offset))
|
||||
|
||||
// gesture end
|
||||
if sender.state == .Ended {
|
||||
if scrollView.center.y > viewHalfHeight+40 || scrollView.center.y < viewHalfHeight-40 {
|
||||
if scrollView.center.y > viewHalfHeight + minOffset || scrollView.center.y < viewHalfHeight - minOffset {
|
||||
|
||||
backgroundView.backgroundColor = self.view.backgroundColor
|
||||
determineAndClose()
|
||||
return
|
||||
|
||||
|
|
@ -739,6 +751,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
UIView.beginAnimations(nil, context: nil)
|
||||
UIView.setAnimationDuration(animationDuration)
|
||||
UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn)
|
||||
view.backgroundColor = UIColor.blackColor()
|
||||
scrollView.center = CGPoint(x: finalX, y: finalY)
|
||||
UIView.commitAnimations()
|
||||
}
|
||||
|
|
@ -750,11 +763,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
view.hidden = true
|
||||
pagingScrollView.alpha = 0.0
|
||||
|
||||
let fadeView = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
|
||||
fadeView.backgroundColor = .blackColor()
|
||||
fadeView.alpha = 0.0
|
||||
applicationWindow.addSubview(fadeView)
|
||||
backgroundView.alpha = 0
|
||||
|
||||
if let sender = delegate?.viewForPhoto?(self, index: initialPageIndex) ?? senderViewForAnimation {
|
||||
|
||||
|
|
@ -762,8 +771,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
sender.hidden = true
|
||||
|
||||
let imageFromView = (senderOriginImage ?? getImageFromView(sender)).rotateImageByOrientation()
|
||||
let screenScale = applicationWindow.frame.width / applicationWindow.frame.height
|
||||
let imageScale = imageFromView.size.width / imageFromView.size.height
|
||||
let imageRatio = imageFromView.size.width / imageFromView.size.height
|
||||
let finalImageViewFrame:CGRect
|
||||
|
||||
resizableImageView = UIImageView(image: imageFromView)
|
||||
|
|
@ -772,14 +780,14 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
resizableImageView.contentMode = .ScaleAspectFill
|
||||
applicationWindow.addSubview(resizableImageView)
|
||||
|
||||
if screenScale < imageScale {
|
||||
if screenRatio < imageRatio {
|
||||
let width = applicationWindow.frame.width
|
||||
let height = width / imageScale
|
||||
let height = width / imageRatio
|
||||
let yOffset = (applicationWindow.frame.height - height) / 2
|
||||
finalImageViewFrame = CGRect(x: 0, y: yOffset, width: width, height: height)
|
||||
} else {
|
||||
let height = applicationWindow.frame.height
|
||||
let width = height * imageScale
|
||||
let width = height * imageRatio
|
||||
let xOffset = (applicationWindow.frame.width - width) / 2
|
||||
finalImageViewFrame = CGRect(x: xOffset, y: 0, width: width, height: height)
|
||||
}
|
||||
|
|
@ -792,7 +800,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
UIView.animateWithDuration(animationDuration, delay:0, usingSpringWithDamping:animationDamping, initialSpringVelocity:0, options:.CurveEaseInOut, animations: { () -> Void in
|
||||
|
||||
fadeView.alpha = 1.0
|
||||
self.backgroundView.alpha = 1.0
|
||||
self.resizableImageView.frame = finalImageViewFrame
|
||||
|
||||
if self.displayCloseButton == true {
|
||||
|
|
@ -814,15 +822,16 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
},
|
||||
completion: { (Bool) -> Void in
|
||||
self.view.hidden = false
|
||||
self.backgroundView.hidden = true
|
||||
self.pagingScrollView.alpha = 1.0
|
||||
self.resizableImageView.alpha = 0.0
|
||||
fadeView.removeFromSuperview()
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
UIView.animateWithDuration(animationDuration, delay:0, usingSpringWithDamping:animationDamping, initialSpringVelocity:0, options:.CurveEaseInOut, animations: { () -> Void in
|
||||
fadeView.alpha = 1.0
|
||||
|
||||
self.backgroundView.alpha = 1.0
|
||||
if self.displayCloseButton == true {
|
||||
self.closeButton.alpha = 1.0
|
||||
self.closeButton.frame = self.closeButtonShowFrame
|
||||
|
|
@ -843,7 +852,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
completion: { (Bool) -> Void in
|
||||
self.view.hidden = false
|
||||
self.pagingScrollView.alpha = 1.0
|
||||
fadeView.removeFromSuperview()
|
||||
self.backgroundView.hidden = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -851,6 +860,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
public func performCloseAnimationWithScrollView(scrollView: SKZoomingScrollView) {
|
||||
|
||||
view.hidden = true
|
||||
backgroundView.hidden = false
|
||||
backgroundView.alpha = 1
|
||||
|
||||
statusBarStyle = isStatusBarOriginallyHidden ? nil : originalStatusBarStyle
|
||||
setNeedsStatusBarAppearanceUpdate()
|
||||
|
|
@ -859,7 +870,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
senderViewOriginalFrame = (sender.superview?.convertRect(sender.frame, toView:nil))!
|
||||
}
|
||||
|
||||
let fadeView = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
|
||||
let contentOffset = scrollView.contentOffset
|
||||
let scrollFrame = scrollView.photoImageView.frame
|
||||
let offsetY = scrollView.center.y - (scrollView.bounds.height/2)
|
||||
|
|
@ -870,11 +880,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
width: scrollFrame.width,
|
||||
height: scrollFrame.height)
|
||||
|
||||
fadeView.backgroundColor = .blackColor()
|
||||
fadeView.alpha = 1.0
|
||||
|
||||
applicationWindow.addSubview(fadeView)
|
||||
resizableImageView.image = scrollView.photo.underlyingImage.rotateImageByOrientation()
|
||||
resizableImageView.image = scrollView.photo?.underlyingImage.rotateImageByOrientation() ?? resizableImageView.image
|
||||
resizableImageView.frame = frame
|
||||
resizableImageView.alpha = 1.0
|
||||
resizableImageView.clipsToBounds = true
|
||||
|
|
@ -888,12 +894,12 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate {
|
|||
}
|
||||
|
||||
UIView.animateWithDuration(animationDuration, delay:0, usingSpringWithDamping:animationDamping, initialSpringVelocity:0, options:.CurveEaseInOut, animations: { () -> () in
|
||||
fadeView.alpha = 0.0
|
||||
self.backgroundView.alpha = 0.0
|
||||
self.resizableImageView.layer.frame = self.senderViewOriginalFrame
|
||||
},
|
||||
completion: { (Bool) -> () in
|
||||
self.resizableImageView.removeFromSuperview()
|
||||
fadeView.removeFromSuperview()
|
||||
self.backgroundView.removeFromSuperview()
|
||||
self.dismissPhotoBrowser()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
</connections>
|
||||
</collectionView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="l1U-c1-FNM" firstAttribute="top" secondItem="f1m-3Z-8mE" secondAttribute="bottom" id="D1M-80-UYO"/>
|
||||
<constraint firstAttribute="trailing" secondItem="f1m-3Z-8mE" secondAttribute="trailing" id="UY9-Uk-tuW"/>
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ class CameraRollViewController: UIViewController, SKPhotoBrowserDelegate, UIColl
|
|||
browser.bounceAnimation = true
|
||||
browser.displayDeleteButton = true
|
||||
browser.displayAction = false
|
||||
browser.statusBarStyle = .LightContent
|
||||
self.presentViewController(browser, animated: true, completion: {})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
|
|||
|
||||
// MARK: - SKPhotoBrowserDelegate
|
||||
func didShowPhotoAtIndex(index: Int) {
|
||||
// do some handle if you need
|
||||
collectionView.visibleCells().forEach({$0.hidden = false})
|
||||
collectionView.cellForItemAtIndexPath(NSIndexPath(forItem: index, inSection: 0))?.hidden = true
|
||||
}
|
||||
|
||||
func willDismissAtPageIndex(index: Int) {
|
||||
|
|
@ -122,6 +123,10 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
|
|||
|
||||
return collectionView.cellForItemAtIndexPath(NSIndexPath(forItem: index, inSection: 0))
|
||||
}
|
||||
|
||||
override func preferredStatusBarStyle() -> UIStatusBarStyle {
|
||||
return .LightContent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 MiB After Width: | Height: | Size: 3.2 MiB |
Loading…
Reference in New Issue