Fix layout for SPStorkController

- Fix layout for SPStorkController
- Add extenshion for `CGRect` static var `displayFrame`. It is rect for screen size
- Set clear background color for `SPStorkIndicatorView`
This commit is contained in:
Ivan Vorobei
2018-11-29 12:49:56 +03:00
parent 25ea7eab4c
commit 425f8ec1ca
6 changed files with 43 additions and 16 deletions
@@ -23,6 +23,11 @@ import UIKit
extension CGRect {
static var displayFrame: CGRect {
let screenSize = UIScreen.main.bounds
return CGRect.init(origin: .zero, size: screenSize.size)
}
var bottomXPosition: CGFloat {
get {
return self.origin.x + self.width
@@ -31,7 +31,6 @@ final class SPStorkDismissingAnimationController: NSObject, UIViewControllerAnim
let containerView = transitionContext.containerView
let offscreenFrame = CGRect(x: 0, y: containerView.bounds.height, width: containerView.bounds.width, height: containerView.bounds.height)
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
delay: 0,
@@ -41,7 +40,7 @@ final class SPStorkDismissingAnimationController: NSObject, UIViewControllerAnim
animations: {
presentedViewController.view.frame = offscreenFrame
}) { finished in
transitionContext.completeTransition(finished)
transitionContext.completeTransition(finished)
}
}
@@ -47,6 +47,7 @@ class SPStorkIndicatorView: UIView {
init() {
super.init(frame: .zero)
self.backgroundColor = UIColor.clear
self.addSubview(self.leftView)
self.addSubview(self.rightView)
self.leftView.backgroundColor = UIColor.init(hex: "CAC9CF")
@@ -58,6 +58,7 @@ final class SPStorkPresentationController: UIPresentationController, UIGestureRe
private func updateLayout() {
guard let presentedView = self.presentedView else { return }
self.indicatorView.style = .line
self.indicatorView.sizeToFit()
self.indicatorView.frame.origin.y = 12
self.indicatorView.center.x = presentedView.frame.width / 2
@@ -65,7 +66,7 @@ final class SPStorkPresentationController: UIPresentationController, UIGestureRe
override var frameOfPresentedViewInContainerView: CGRect {
if let containerView = self.containerView {
let yOffset = topSpace + 13
let yOffset: CGFloat = topSpace + 13
return CGRect(x: 0, y: yOffset, width: containerView.bounds.width, height: containerView.bounds.height - yOffset)
} else {
return .zero
@@ -88,8 +89,10 @@ final class SPStorkPresentationController: UIPresentationController, UIGestureRe
guard let transitionCoordinator = self.presentingViewController.transitionCoordinator else { return }
transitionCoordinator.animateAlongsideTransition(in: self.presentingViewController.view, animation: { _ in
self.presentingViewController.view.transform = self.transform
self.presentingViewController.view.alpha = self.alpha
if !self.isPresentingControllerUseStork {
self.presentingViewController.view.transform = self.transform
self.presentingViewController.view.alpha = self.alpha
}
})
}
@@ -112,15 +115,22 @@ final class SPStorkPresentationController: UIPresentationController, UIGestureRe
transitionCoordinator.animateAlongsideTransition(in: presentingViewController.view, animation: { _ in
self.presentingViewController.view.transform = CGAffineTransform.identity
if self.presentingViewController.view.frame.origin != CGPoint.zero {
self.presentingViewController.view.frame = CGRect.displayFrame
}
})
self.presentingViewController.view.addCornerRadiusAnimation(to: 0, duration: 0.6)
if !self.isPresentingControllerUseStork {
self.presentingViewController.view.addCornerRadiusAnimation(to: 0, duration: 0.6)
}
}
override func dismissalTransitionDidEnd(_ completed: Bool) {
if let presentingView = self.presentingViewController.view {
presentingView.layer.cornerRadius = 0
presentingView.layer.masksToBounds = false
if !self.isPresentingControllerUseStork {
if let presentingView = self.presentingViewController.view {
presentingView.layer.cornerRadius = 0
presentingView.layer.masksToBounds = false
}
}
}
}
@@ -158,8 +168,10 @@ extension SPStorkPresentationController {
options: [.curveEaseOut, .allowUserInteraction],
animations: {
self.presentedView?.transform = .identity
self.presentingViewController.view.transform = self.transform
self.presentingViewController.view.alpha = self.alpha
if !self.isPresentingControllerUseStork {
self.presentingViewController.view.transform = self.transform
self.presentingViewController.view.alpha = self.alpha
}
})
}
default:
@@ -185,9 +197,19 @@ extension SPStorkPresentationController {
self.presentedView?.transform = CGAffineTransform(translationX: 0, y: translationForModal)
let factor = 1 + (translationForModal / 6000)
self.presentingViewController.view.transform = self.transform.scaledBy(x: factor, y: factor)
self.presentingViewController.view.alpha = self.alpha + ((factor - 1) * 15)
if !self.isPresentingControllerUseStork {
let factor = 1 + (translationForModal / 6000)
self.presentingViewController.view.transform = self.transform.scaledBy(x: factor, y: factor)
self.presentingViewController.view.alpha = self.alpha + ((factor - 1) * 15)
}
}
}
private var isPresentingControllerUseStork: Bool {
let controller = self.presentingViewController
return controller.transitioningDelegate is SPStorkTransitioningDelegate
&& controller.modalPresentationStyle == .custom
&& controller.presentingViewController != nil
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
# SPStorkController
Modal controller as in mail or Apple music application. Similar animation and transition. Now in develop
Modal controller as in mail or Apple music application. Similar animation and transition. I tried to repeat all the animations, corner radius and frames. The controller supports gestures
Preview GIF loading `4mb`. Please, wait
@@ -15,7 +15,7 @@ The project is absolutely free, but but it takes time to support and update it.
Swift 4.2. Ready for use on iOS 10+
## Integration
Drop in `source/sparrow` folder to your Xcode project. Make sure to enable `Copy items if needed` and `Create groups`
Drop in `Source/Sparrow` folder to your Xcode project. Make sure to enable `Copy items if needed` and `Create groups`
Or via CocoaPods:
```ruby