diff --git a/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate b/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate index 1275e96..660866d 100644 Binary files a/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate and b/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/stork-controller/Frameworks/sparrow/extension/SPCGRectExtension.swift b/Example/stork-controller/Frameworks/sparrow/extension/SPCGRectExtension.swift index 957667e..ec05690 100644 --- a/Example/stork-controller/Frameworks/sparrow/extension/SPCGRectExtension.swift +++ b/Example/stork-controller/Frameworks/sparrow/extension/SPCGRectExtension.swift @@ -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 diff --git a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkDismissingAnimationController.swift b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkDismissingAnimationController.swift index 31a75e5..8728eac 100644 --- a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkDismissingAnimationController.swift +++ b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkDismissingAnimationController.swift @@ -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) } } diff --git a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkIndicatorView.swift b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkIndicatorView.swift index ea102b2..14b0220 100644 --- a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkIndicatorView.swift +++ b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkIndicatorView.swift @@ -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") diff --git a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkPresentationController.swift b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkPresentationController.swift index 12d208d..08dfe3e 100644 --- a/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkPresentationController.swift +++ b/Example/stork-controller/Frameworks/sparrow/ui/controllers/stork/SPStorkPresentationController.swift @@ -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 + } } diff --git a/README.md b/README.md index 2e1a530..34b01d3 100644 --- a/README.md +++ b/README.md @@ -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