Compare commits

...

14 Commits

Author SHA1 Message Date
Ivan Vorobei 0309bb2e0e Update example and Readme 2018-11-30 20:43:35 +03:00
Ivan Vorobei 4e0507f132 Update README.md 2018-11-30 20:33:04 +03:00
Ivan Vorobei 8e33ff7614 Add donate banner 2018-11-30 20:32:36 +03:00
Ivan Vorobei b7ab9e0327 Update README.md 2018-11-30 20:30:39 +03:00
Ivan Vorobei 4129f23d00 Add header banner 2018-11-30 20:29:57 +03:00
Ivan Vorobei 91b01d83d9 Update Readme 2018-11-30 20:26:33 +03:00
Ivan Vorobei 4eda691bd0 Update README.md 2018-11-30 20:25:06 +03:00
Ivan Vorobei 0889352299 Update Readme 2018-11-30 20:18:38 +03:00
Ivan Vorobei 34f267d43c Update SPStorkController.podspec 2018-11-29 12:55:29 +03:00
Ivan Vorobei 425f8ec1ca 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`
2018-11-29 12:49:56 +03:00
Ivan Vorobei 25ea7eab4c Add more interactive to SPStorkController 2018-11-29 11:10:18 +03:00
Ivan Vorobei 16f060820f Update README.md 2018-11-28 20:11:41 +03:00
Ivan Vorobei 4c8faf7695 Update README.md 2018-11-28 17:49:37 +03:00
Ivan Vorobei 5b843582d4 Update README.md 2018-11-28 17:30:29 +03:00
14 changed files with 1302 additions and 991 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,30 @@
// The MIT License (MIT)
// Copyright © 2017 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import UIKit
extension UIVisualEffectView {
convenience init(style: UIBlurEffect.Style) {
let effect = UIBlurEffect(style: .extraLight)
self.init(effect: effect)
}
}
@@ -0,0 +1,186 @@
import UIKit
public class SPFakeBarView: UIView {
var style: Style = . small {
didSet {
self.updateStyle()
}
}
private var settedHeight: CGFloat = 0
var height: CGFloat {
get {
return (self.settedHeight) + (self.addStatusBarHeight ? UIViewController.statusBarHeight : 0)
}
set {
self.settedHeight = newValue
self.updateHeight()
}
}
var addStatusBarHeight: Bool = true {
didSet {
self.updateHeight()
}
}
var elementsColor: UIColor = UINavigationController.elementsColor {
didSet {
self.leftButton.setTitleColor(self.elementsColor)
self.rightButton.setTitleColor(self.elementsColor)
}
}
var titleLabel = UILabel.init()
var subtitleLabel = UILabel.init()
var leftButton = UIButton.init()
var rightButton = UIButton.init()
private var titleBottomConstraint: NSLayoutConstraint?
private var heightConstraint: NSLayoutConstraint?
private var topConstraint: NSLayoutConstraint?
private var leadingConstraint: NSLayoutConstraint?
private var trailingConstraint: NSLayoutConstraint?
private let blurView = UIVisualEffectView.init(style: .extraLight)
private let separatorView = UIView()
init(style: Style) {
super.init(frame: CGRect.zero)
self.style = style
self.commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.style = .small
self.commonInit()
}
private func commonInit() {
self.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(self.blurView)
self.blurView.translatesAutoresizingMaskIntoConstraints = false
self.blurView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.blurView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.blurView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
self.blurView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
self.addSubview(self.separatorView)
self.separatorView.backgroundColor = UIColor.init(hex: "BFBFBF")
self.separatorView.translatesAutoresizingMaskIntoConstraints = false
self.separatorView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.separatorView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.separatorView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
self.separatorView.heightAnchor.constraint(equalToConstant: 0.5).isActive = true
self.addSubview(self.titleLabel)
self.titleLabel.translatesAutoresizingMaskIntoConstraints = false
self.titleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 16).isActive = true
self.titleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16).isActive = true
self.titleBottomConstraint = self.titleLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -12)
self.titleBottomConstraint?.isActive = true
self.addSubview(self.subtitleLabel)
self.subtitleLabel.textColor = UIColor.init(hex: "8E8E92")
self.subtitleLabel.font = UIFont.system(type: .DemiBold, size: 13)
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
self.subtitleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 16).isActive = true
self.subtitleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16).isActive = true
self.subtitleLabel.bottomAnchor.constraint(equalTo: self.titleLabel.topAnchor, constant: 0).isActive = true
self.leftButton.setTitleColor(self.elementsColor)
self.leftButton.titleLabel?.textAlignment = .left
self.leftButton.titleLabel?.font = UIFont.system(type: .Regular, size: 17)
self.leftButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 17, bottom: 0, right: 0)
self.addSubview(self.leftButton)
self.leftButton.translatesAutoresizingMaskIntoConstraints = false
self.leftButton.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.leftButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -12).isActive = true
self.rightButton.setTitleColor(self.elementsColor)
self.rightButton.titleLabel?.textAlignment = .right
self.rightButton.titleLabel?.font = UIFont.system(type: .Regular, size: 17)
self.rightButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 17)
self.addSubview(self.rightButton)
self.rightButton.translatesAutoresizingMaskIntoConstraints = false
self.rightButton.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.rightButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -12).isActive = true
self.setContraints()
self.updateStyle()
}
public override func layoutSubviews() {
super.layoutSubviews()
self.setContraints()
}
private func setContraints() {
if let superview = self.superview {
if self.topConstraint == nil {
self.topConstraint = self.topAnchor.constraint(equalTo: superview.topAnchor)
self.topConstraint?.isActive = true
self.leadingConstraint = self.leadingAnchor.constraint(equalTo: superview.leadingAnchor)
self.leadingConstraint?.isActive = true
self.trailingConstraint = self.trailingAnchor.constraint(equalTo: superview.trailingAnchor)
self.trailingConstraint?.isActive = true
self.heightConstraint = self.heightAnchor.constraint(equalToConstant: self.height)
self.heightConstraint?.isActive = true
self.updateHeight()
}
}
}
private func updateStyle() {
switch self.style {
case .small:
if UIViewController.statusBarHeight == 44 {
self.height = 88 - 44
self.titleBottomConstraint?.constant = -12
} else {
self.height = 64 - 20
self.titleBottomConstraint?.constant = -12
}
self.addStatusBarHeight = true
self.titleLabel.font = UIFont.system(type: .DemiBold, size: 17)
self.titleLabel.setCenteringAlignment()
case .stork:
self.height = 66
self.titleBottomConstraint?.constant = -12
self.addStatusBarHeight = false
self.titleLabel.font = UIFont.system(type: .DemiBold, size: 17)
self.titleLabel.setCenteringAlignment()
case .large:
if UIViewController.statusBarHeight == 44 {
self.height = 140 - 44
self.titleBottomConstraint?.constant = -8
} else {
self.height = 112 - 20
self.titleBottomConstraint?.constant = -4
}
self.addStatusBarHeight = true
self.titleLabel.font = UIFont.system(type: .Bold, size: 34)
self.titleLabel.textAlignment = .left
break
}
self.updateConstraints()
}
private func updateHeight() {
self.heightConstraint?.constant = self.height
self.updateConstraints()
}
enum Style {
case small
case large
case stork
}
}
@@ -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
@@ -25,7 +25,11 @@ extension UINavigationController {
static var elementsColor: UIColor {
get {
return UINavigationBar.appearance().tintColor
if UINavigationBar.appearance().tintColor != nil {
return UINavigationBar.appearance().tintColor
} else {
return SPNativeStyleKit.Colors.blue
}
}
set {
UINavigationBar.appearance().tintColor = newValue
@@ -129,6 +129,7 @@ extension UIViewController {
switch style {
case .large:
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always
}
case .small:
@@ -154,6 +155,10 @@ extension UIViewController {
}
var statusBarHeight: CGFloat {
return UIViewController.statusBarHeight
}
static var statusBarHeight: CGFloat {
return UIApplication.shared.statusBarFrame.height
}
}
@@ -276,6 +276,10 @@ extension UIView {
self.isHidden = true
})
}
func removeAllAnimations() {
self.layer.removeAllAnimations()
}
}
// MARK: - corner radius
@@ -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
}
}
}
}
@@ -134,16 +144,8 @@ extension SPStorkPresentationController {
switch gestureRecognizer.state {
case .began:
/*UIView.animate(
withDuration: 0.25,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: .curveEaseOut,
animations: {
self.indicatorView.transform = CGAffineTransform.init(scaleX: 1.2, y: 1.2)
})*/
self.indicatorView.style = .line
self.presentingViewController.view.removeAllAnimations()
gestureRecognizer.setTranslation(CGPoint(x: 0, y: 0), in: containerView)
case .changed:
if self.isSwipeToDismissEnabled {
@@ -163,11 +165,13 @@ extension SPStorkPresentationController {
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: .curveEaseOut,
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:
@@ -193,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
}
}
+13 -1
View File
@@ -6,6 +6,8 @@ class ViewController: SPStatusBarManagerViewController {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(self.viewWasTapped))
view.addGestureRecognizer(tap)
print("Tap anymore for present modal controller")
}
@objc func viewWasTapped() {
@@ -19,16 +21,26 @@ class ViewController: SPStatusBarManagerViewController {
class ModalViewController: UIViewController {
let navBar = SPFakeBarView(style: .stork)
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
self.modalPresentationCapturesStatusBarAppearance = true
let tap = UITapGestureRecognizer(target: self, action: #selector(self.viewWasTapped))
view.addGestureRecognizer(tap)
self.navBar.titleLabel.text = "Title"
self.navBar.leftButton.setTitle("Cancel")
self.navBar.leftButton.target {
self.dismiss()
}
self.view.addSubview(self.navBar)
}
@objc func viewWasTapped() {
self.dismiss(animated: true, completion: nil)
self.dismiss()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
+54 -11
View File
@@ -1,21 +1,22 @@
# SPStorkController
Modal controller as in mail or Apple music application. Similar animation and transition. Now in develop
<img src="https://rawcdn.githack.com/IvanVorobei/SPStorkController/90c836ec5649e77fb44ff727d7dad96d2009f3d8/Resources/SPStorkController - Name.svg"/>
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
<img src="https://rawcdn.githack.com/IvanVorobei/SPStorkController/0acd51bbe76ef48611e1bdd408aebb9c7d9b0ae6/resources/gif-mockup.gif" width="500">
<img src="https://rawcdn.githack.com/IvanVorobei/RequestPermission/6fcd9bdb50a99cea358294999e161dffe55be46f/resources/request-permission - donate.svg"/>
<img src="https://rawcdn.githack.com/IvanVorobei/SPStorkController/4b1c91dacc4d3f901fcab5c7efdff256a40c4381/Resources/SPStorkController - Donate.svg"/>
The project is absolutely free, but but it takes time to support and update it. Your support is very motivating and very important. I often receive emails asking me to update or add functionality. [Small donate](https://money.yandex.ru/to/410012745748312) for a cup of coffee helps to develop the project and make it better
<img src="https://rawcdn.githack.com/IvanVorobei/RequestPermission/6fcd9bdb50a99cea358294999e161dffe55be46f/resources/request-permission - donate.svg"/>
<img src="https://rawcdn.githack.com/IvanVorobei/SPStorkController/4b1c91dacc4d3f901fcab5c7efdff256a40c4381/Resources/SPStorkController - Donate.svg"/>
## Requirements
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
@@ -28,17 +29,59 @@ import SparrowKit
```
## How to use
Init controller (please, set background, it maybe clear color) and set `transitioningDelegate`. Use `present` or `dissmiss` funcs:
Create controller (please, set background, it maybe clear color) and set `transitioningDelegate` to `SPStorkTransitioningDelegate()`. Use `present` or `dismiss` functions:
```swift
import SparrowKit
let controller = UIViewController()
let transitionDelegate = SPStorkTransitioningDelegate()
controller.transitioningDelegate = transitionDelegate
controller.transitioningDelegate = SPStorkTransitioningDelegate()
controller.modalPresentationStyle = .custom
present(controller, animated: true, completion: nil)
```
## Add Navigation Bar
You may want to add a navigation bar to your modal controller. Since it became impossible to change or customize the native controller in swift 4 (I couldnt even find a way to change the height of bar), I completely create navigation bar. Visually, it looks real, but it doesnt execute the necessary functions
```swift
import UIKit
class ModalController: Controller {
let navBar = SPFakeBarView(style: .stork)
override func viewDidLoad() {
super.viewDidLoad()
self.navBar.titleLabel.text = "Title"
self.navBar.leftButton.setTitle("Cancel")
self.navBar.leftButton.target {
self.dismiss()
}
self.view.addSubview(self.navBar)
}
}
```
You only need to add a navigation bar to the main view, it will automatically layout. Use style `.stork` in init `SPFakeBarView`. It is image preview with Navigation Bar and without it:
<img src="https://rawcdn.githack.com/IvanVorobei/SPStorkController/916cfef888b3e70ca45d1b8b26fba1947421632b/Recources/SPStorkController - Banner.jpg"/>
## My projects
Here I would like to offer you my other projects
### SPPermission
Project [SPPermission](https://github.com/IvanVorobei/SPPermission) for managing permissions with the customizable visual effects. Beautiful dialog increases the chance of approval (which is important when we request notification). Simple control of this module saves you hours of development. You can start using [this project](https://github.com/IvanVorobei/SPPermission) with just two lines of code and easy customization!
<img src="https://rawcdn.githack.com/IvanVorobei/RequestPermission/fb53d20f152a3e76e053e6af529306611fb794f0/resources/request-permission - mockup_preview.gif" width="500">
### SparrowKit
The `SPStorkController` use [SparrowKit](https://github.com/IvanVorobei/SparrowKit) library. You can install it if you want to receive updates often. Also in library you can find [SPPermission](https://github.com/IvanVorobei/SPPermission) and other useful extensions. For install via CocoaPods use:
```ruby
pod 'SparrowKit'
```
If you use `pod SPStorkController`, library [SparrowKit](https://github.com/IvanVorobei/SparrowKit) install automatically.
## License
`SPStorkController` is released under the MIT license. Check LICENSE.md for details
@@ -47,4 +90,4 @@ If you need develop application or UI, write me to hello@ivanvorobei.by. I am de
[hello.ivanvorobei.by](https://hello.ivanvorobei.by) & [ivanvorobei.by](https://hello.ivanvorobei.by)
My apps [in AppStore](https://itunes.apple.com/us/developer/polina-zubarik/id1434528595) & [in AppStore 2](https://itunes.apple.com/us/developer/mikalai-varabei/id1435792103)
My apps [in AppStore](https://itunes.apple.com/us/developer/polina-zubarik/id1434528595) & [in AppStore 2](https://itunes.apple.com/us/developer/mikalai-varabei/id1435792103)
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SPStorkController"
s.version = "1.0.4"
s.version = "1.0.8"
s.summary = "Modal controller as mail or Apple music application"
s.homepage = "https://github.com/IvanVorobei/SPStorkController"
s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version }
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = "10.0"
s.dependency 'SparrowKit', '~> 1.0.0'
s.dependency 'SparrowKit', '~> 1.0.2'
end