Commit 94c6f356 by Dmitriy Stepanets

Experiments

parent 21eee6bc
......@@ -3,4 +3,70 @@
uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6"
type = "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>
......@@ -8,35 +8,22 @@
import UIKit
class DayControlsNavigationBar: UINavigationBar {
private let customView = UIView()
private var contentView:UIView?
private var currentProgress:CGFloat = 0
private var savedProgress:CGFloat = 0
var controlsHeight:CGFloat = 0
private var defaultYOffset:CGFloat = 0
override init(frame: CGRect) {
super.init(frame: frame)
customView.backgroundColor = .lightGray
isTranslucent = true
}
override func layoutSubviews() {
super.layoutSubviews()
guard let contentView = self.contentView else {
self.findAndSetupContentView()
return
if frame.origin.y != 0 && defaultYOffset == 0 {
self.defaultYOffset = frame.origin.y
}
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) {
......@@ -49,14 +36,8 @@ class DayControlsNavigationBar: UINavigationBar {
progress = min(progress, 1)
self.currentProgress = progress
self.contentView?.frame.origin.y = -controlsHeight * progress
self.contentView?.subviews.forEach {
if $0 != customView {
$0.alpha = 1 - progress
}
}
self.customView.alpha = progress
self.frame.origin.y = defaultYOffset - self.frame.height * progressValue
self.alpha = 1 - progressValue
}
public func saveProgress() {
......@@ -64,21 +45,15 @@ class DayControlsNavigationBar: UINavigationBar {
}
public func restoreProgress() {
currentProgress = savedProgress
showControls(progressValue: currentProgress)
savedProgress = 0
}
//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
}
let diff = (savedProgress - currentProgress) * 100
let numerOfSteps = Int((diff / 60 * 0.35 * 100).rounded(.up))
for step in 0..<numerOfSteps {
showControls(progressValue: CGFloat(step) / CGFloat(numerOfSteps))
}
// currentProgress = savedProgress
// showControls(progressValue: currentProgress)
// savedProgress = 0
}
}
......@@ -29,10 +29,6 @@ class DayControlsNavigatoinController: UINavigationController {
let popViewController = super.popViewController(animated: animated)
dayControllsNavBar?.restoreProgress()
// transitionCoordinator?.animate(alongsideTransition: nil, completion: {[weak self] _ in
// self?.dayControllsNavBar?.restoreProgress()
// })
return popViewController
}
}
......
......@@ -10,6 +10,7 @@ import UIKit
class ForecastViewController: UIViewController {
//Private
private let cityButton = NavigationCityButton()
private let daysStackView = UIStackView()
private let tableView = UITableView()
private let viewModel:ForecastViewModel
private var localizationObserver:Any?
......@@ -31,6 +32,7 @@ class ForecastViewController: UIViewController {
prepareViewController()
prepareNavigationBar()
prepareTableView()
prepareDaysStackView()
refreshCityButton()
}
......@@ -48,7 +50,7 @@ class ForecastViewController: UIViewController {
}
}
//MARk:- Prepare
//MARK:- Prepare
private extension ForecastViewController {
func prepareViewController() {
view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
......@@ -80,6 +82,18 @@ private extension ForecastViewController {
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() {
viewModel.forecastCellFactory.registerCells(on: tableView)
tableView.contentInset = .init(top: 0, left: 0, bottom: 15, right: 0)
......
......@@ -15,6 +15,16 @@ class TodayViewController: UIViewController {
private let tableView = UITableView()
private var dayControlsNavigationBar:DayControlsNavigationBar?
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 {
if let observer = localizationObserver {
......@@ -38,6 +48,16 @@ class TodayViewController: UIViewController {
prepareNavigationBar()
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.updateWeather()
}
......@@ -132,10 +152,10 @@ extension TodayViewController: UITableViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let cellFrame = viewModel.todayCellFactory.forecastPeriodCellFrame
guard cellFrame.origin.y > 0 else { return }
let controlsHeight = dayControlsNavigationBar?.controlsHeight ?? 0
let controlsHeight:CGFloat = 50
let startPointY = cellFrame.origin.y + cellFrame.height - controlsHeight
if scrollView.contentOffset.y >= startPointY {
let cellOffset = scrollView.contentOffset.y - startPointY
let progress = cellOffset / controlsHeight
......
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