Commit 94c6f356 by Dmitriy Stepanets

Experiments

parent 21eee6bc
...@@ -3,4 +3,70 @@ ...@@ -3,4 +3,70 @@
uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6" uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6"
type = "0" type = "0"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "89C8A0DD-3D0D-4C33-BA19-94E6A7991DA2"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/Helpers/DayControlsNavigationBar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "50"
endingLineNumber = "50"
landmarkName = "restoreProgress()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "14AFAEC9-A39D-4B7B-9B2D-C2DA2519300A"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/Helpers/DayControlsNavigationBar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "showControls(progressValue:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D794B66E-D7A6-4A78-A1CE-C34AC9DC948E"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/Helpers/DayControlsNavigationBar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "51"
endingLineNumber = "51"
landmarkName = "restoreProgress()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "2AD266BE-E133-463F-BF26-2797D4C1A0EF"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/Helpers/DayControlsNavigationBar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "showControls(progressValue:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>
...@@ -8,35 +8,22 @@ ...@@ -8,35 +8,22 @@
import UIKit import UIKit
class DayControlsNavigationBar: UINavigationBar { class DayControlsNavigationBar: UINavigationBar {
private let customView = UIView()
private var contentView:UIView?
private var currentProgress:CGFloat = 0 private var currentProgress:CGFloat = 0
private var savedProgress:CGFloat = 0 private var savedProgress:CGFloat = 0
var controlsHeight:CGFloat = 0 private var defaultYOffset:CGFloat = 0
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
customView.backgroundColor = .lightGray isTranslucent = true
} }
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard let contentView = self.contentView else { if frame.origin.y != 0 && defaultYOffset == 0 {
self.findAndSetupContentView() self.defaultYOffset = frame.origin.y
return
} }
print("Layout subviews")
let targetHeight = contentView.frame.height * 2
self.contentView?.frame.size.height = targetHeight
self.customView.frame = .init(x: contentView.frame.origin.x,
y: targetHeight / 2,
width: contentView.frame.width,
height: targetHeight / 2)
self.controlsHeight = targetHeight / 2
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
...@@ -49,14 +36,8 @@ class DayControlsNavigationBar: UINavigationBar { ...@@ -49,14 +36,8 @@ class DayControlsNavigationBar: UINavigationBar {
progress = min(progress, 1) progress = min(progress, 1)
self.currentProgress = progress self.currentProgress = progress
self.contentView?.frame.origin.y = -controlsHeight * progress self.frame.origin.y = defaultYOffset - self.frame.height * progressValue
self.contentView?.subviews.forEach { self.alpha = 1 - progressValue
if $0 != customView {
$0.alpha = 1 - progress
}
}
self.customView.alpha = progress
} }
public func saveProgress() { public func saveProgress() {
...@@ -64,21 +45,15 @@ class DayControlsNavigationBar: UINavigationBar { ...@@ -64,21 +45,15 @@ class DayControlsNavigationBar: UINavigationBar {
} }
public func restoreProgress() { public func restoreProgress() {
currentProgress = savedProgress let diff = (savedProgress - currentProgress) * 100
showControls(progressValue: currentProgress) let numerOfSteps = Int((diff / 60 * 0.35 * 100).rounded(.up))
savedProgress = 0 for step in 0..<numerOfSteps {
showControls(progressValue: CGFloat(step) / CGFloat(numerOfSteps))
} }
//Private
private func findAndSetupContentView() {
subviews.forEach {
if String(cString: class_getName($0.classForCoder)) == "_UINavigationBarContentView" {
self.contentView = $0
self.contentView?.clipsToBounds = false
self.contentView?.addSubview(customView)
self.customView.alpha = 0 // currentProgress = savedProgress
} // showControls(progressValue: currentProgress)
} // savedProgress = 0
} }
} }
...@@ -29,10 +29,6 @@ class DayControlsNavigatoinController: UINavigationController { ...@@ -29,10 +29,6 @@ class DayControlsNavigatoinController: UINavigationController {
let popViewController = super.popViewController(animated: animated) let popViewController = super.popViewController(animated: animated)
dayControllsNavBar?.restoreProgress() dayControllsNavBar?.restoreProgress()
// transitionCoordinator?.animate(alongsideTransition: nil, completion: {[weak self] _ in
// self?.dayControllsNavBar?.restoreProgress()
// })
return popViewController return popViewController
} }
} }
......
...@@ -10,6 +10,7 @@ import UIKit ...@@ -10,6 +10,7 @@ import UIKit
class ForecastViewController: UIViewController { class ForecastViewController: UIViewController {
//Private //Private
private let cityButton = NavigationCityButton() private let cityButton = NavigationCityButton()
private let daysStackView = UIStackView()
private let tableView = UITableView() private let tableView = UITableView()
private let viewModel:ForecastViewModel private let viewModel:ForecastViewModel
private var localizationObserver:Any? private var localizationObserver:Any?
...@@ -31,6 +32,7 @@ class ForecastViewController: UIViewController { ...@@ -31,6 +32,7 @@ class ForecastViewController: UIViewController {
prepareViewController() prepareViewController()
prepareNavigationBar() prepareNavigationBar()
prepareTableView() prepareTableView()
prepareDaysStackView()
refreshCityButton() refreshCityButton()
} }
...@@ -48,7 +50,7 @@ class ForecastViewController: UIViewController { ...@@ -48,7 +50,7 @@ class ForecastViewController: UIViewController {
} }
} }
//MARk:- Prepare //MARK:- Prepare
private extension ForecastViewController { private extension ForecastViewController {
func prepareViewController() { func prepareViewController() {
view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
...@@ -80,6 +82,18 @@ private extension ForecastViewController { ...@@ -80,6 +82,18 @@ private extension ForecastViewController {
self.navigationItem.rightBarButtonItem = notificationBarButton self.navigationItem.rightBarButtonItem = notificationBarButton
} }
func prepareDaysStackView() {
let dView = UIView()
dView.backgroundColor = .red
view.addSubview(dView)
dView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.height.equalTo(50)
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
}
}
func prepareTableView() { func prepareTableView() {
viewModel.forecastCellFactory.registerCells(on: tableView) viewModel.forecastCellFactory.registerCells(on: tableView)
tableView.contentInset = .init(top: 0, left: 0, bottom: 15, right: 0) tableView.contentInset = .init(top: 0, left: 0, bottom: 15, right: 0)
......
...@@ -15,6 +15,16 @@ class TodayViewController: UIViewController { ...@@ -15,6 +15,16 @@ class TodayViewController: UIViewController {
private let tableView = UITableView() private let tableView = UITableView()
private var dayControlsNavigationBar:DayControlsNavigationBar? private var dayControlsNavigationBar:DayControlsNavigationBar?
private var localizationObserver:Any? private var localizationObserver:Any?
private func getStatusBarHeight() -> CGFloat {
var statusBarHeight: CGFloat = 0
if #available(iOS 13.0, *) {
let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
} else {
statusBarHeight = UIApplication.shared.statusBarFrame.height
}
return statusBarHeight
}
deinit { deinit {
if let observer = localizationObserver { if let observer = localizationObserver {
...@@ -38,6 +48,16 @@ class TodayViewController: UIViewController { ...@@ -38,6 +48,16 @@ class TodayViewController: UIViewController {
prepareNavigationBar() prepareNavigationBar()
prepareTableView() prepareTableView()
let dView = UIView()
dView.backgroundColor = .red
view.addSubview(dView)
dView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.height.equalTo(50)
make.top.equalToSuperview().inset(self.getStatusBarHeight())
}
viewModel.delegate = self viewModel.delegate = self
viewModel.updateWeather() viewModel.updateWeather()
} }
...@@ -133,7 +153,7 @@ extension TodayViewController: UITableViewDelegate { ...@@ -133,7 +153,7 @@ extension TodayViewController: UITableViewDelegate {
let cellFrame = viewModel.todayCellFactory.forecastPeriodCellFrame let cellFrame = viewModel.todayCellFactory.forecastPeriodCellFrame
guard cellFrame.origin.y > 0 else { return } guard cellFrame.origin.y > 0 else { return }
let controlsHeight = dayControlsNavigationBar?.controlsHeight ?? 0 let controlsHeight:CGFloat = 50
let startPointY = cellFrame.origin.y + cellFrame.height - controlsHeight let startPointY = cellFrame.origin.y + cellFrame.height - controlsHeight
if scrollView.contentOffset.y >= startPointY { if scrollView.contentOffset.y >= startPointY {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment