Compare commits

..

8 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
9 changed files with 1246 additions and 960 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
}
}
@@ -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
}
}
+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 {
+45 -4
View File
@@ -1,15 +1,16 @@
# SPStorkController
<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+
@@ -36,11 +37,51 @@ 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
Project [SPPermission](https://github.com/IvanVorobei/SPPermission) about 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 with just two lines of code and easy customization!
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
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SPStorkController"
s.version = "1.0.6"
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.1'
s.dependency 'SparrowKit', '~> 1.0.2'
end