From a93f945fcc07be6fdbd1676d39b8fc2c48bb0c52 Mon Sep 17 00:00:00 2001 From: Kevin Rummler Date: Wed, 16 Mar 2016 16:47:24 +0100 Subject: [PATCH] Added visibility-effect when dragging down to show view behind --- SKPhotoBrowser/SKPhotoBrowser.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index acca656..3f8fab8 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -241,8 +241,9 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { public override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = UIColor.clearColor() + 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() @@ -256,7 +257,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) @@ -698,6 +699,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 @@ -719,12 +721,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.5, 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 @@ -743,6 +748,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() }