Commit 89598404 by Dmitriy Stepanets

Added controls to navigation bar

parent 9254d554
......@@ -38,6 +38,7 @@
CD82300325D69DE400A05501 /* CityConditionsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD82300225D69DE400A05501 /* CityConditionsCell.swift */; };
CD82300725D6A73F00A05501 /* CityConditionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD82300625D6A73E00A05501 /* CityConditionButton.swift */; };
CD82300A25D6B2AF00A05501 /* AppTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD82300925D6B2AF00A05501 /* AppTabBarController.swift */; };
CD8343B925FBEFF60003101F /* DayControlsNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8343B825FBEFF60003101F /* DayControlsNavigationBar.swift */; };
CD86245E25E646350097F3FB /* SunUvView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD86245D25E646350097F3FB /* SunUvView.swift */; };
CD86246125E662BC0097F3FB /* SunUvLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD86246025E662BC0097F3FB /* SunUvLineView.swift */; };
CD86246525E66E8A0097F3FB /* CityPrecipCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD86246425E66E8A0097F3FB /* CityPrecipCell.swift */; };
......@@ -129,6 +130,7 @@
CD82300225D69DE400A05501 /* CityConditionsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityConditionsCell.swift; sourceTree = "<group>"; };
CD82300625D6A73E00A05501 /* CityConditionButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityConditionButton.swift; sourceTree = "<group>"; };
CD82300925D6B2AF00A05501 /* AppTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTabBarController.swift; sourceTree = "<group>"; };
CD8343B825FBEFF60003101F /* DayControlsNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayControlsNavigationBar.swift; sourceTree = "<group>"; };
CD86245D25E646350097F3FB /* SunUvView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SunUvView.swift; sourceTree = "<group>"; };
CD86246025E662BC0097F3FB /* SunUvLineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SunUvLineView.swift; sourceTree = "<group>"; };
CD86246425E66E8A0097F3FB /* CityPrecipCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityPrecipCell.swift; sourceTree = "<group>"; };
......@@ -458,6 +460,7 @@
CDD0F1ED25725BCF00CF5017 /* ThemeManager.swift */,
CD9B6B1025DBC723001D9B80 /* CubicCurveAlgorithm.swift */,
CD86246B25E6826A0097F3FB /* InnerShadowLayer.swift */,
CD8343B825FBEFF60003101F /* DayControlsNavigationBar.swift */,
);
path = Helpers;
sourceTree = "<group>";
......@@ -735,6 +738,7 @@
CDC6126625E9085600188DA7 /* GraphLine.swift in Sources */,
CD86246525E66E8A0097F3FB /* CityPrecipCell.swift in Sources */,
CD80917B2578E4A8003541A4 /* UIViewController+Alert.swift in Sources */,
CD8343B925FBEFF60003101F /* DayControlsNavigationBar.swift in Sources */,
CEDE4F0F25EFA3B4007457E9 /* UpdatableModelObjectInTime.swift in Sources */,
CD3F6E6925FA59D4002DB99B /* ForecastDetailPeriodButton.swift in Sources */,
CD17C5F625D15B4400EE884E /* TodayViewController.swift in Sources */,
......
......@@ -7,7 +7,7 @@
<key>1Weather.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>3</integer>
</dict>
<key>PG (Playground) 1.xcscheme</key>
<dict>
......
......@@ -10,7 +10,7 @@ import UIKit
class TodayCoordinator:Coordinator {
//Private
private let todayViewModel = TodayViewModel(locationManager: LocationManager.shared) // TODO: get rid of singleton maybe?
private let navigationController = UINavigationController(nibName: nil, bundle: nil)
private let navigationController = UINavigationController(navigationBarClass: DayControlsNavigationBar.self, toolbarClass: nil)
private var tabBarController:UITabBarController?
//Public
......
//
// DayControlsNavigatoinBar.swift
// 1Weather
//
// Created by Dmitry Stepanets on 12.03.2021.
//
import UIKit
class DayControlsNavigationBar: UINavigationBar {
private let customView = UIView()
private var contentView:UIView?
var controlsHeight:CGFloat = 0
override init(frame: CGRect) {
super.init(frame: frame)
customView.backgroundColor = .lightGray
}
override func layoutSubviews() {
super.layoutSubviews()
if contentView == nil {
self.findAndSetupContentView()
}
// guard let contentView = self.contentView else {
// self.findAndSetupContentView()
// return
// }
// contentView.frame.origin.y = -30
// customView.frame = .init(x: contentView.frame.origin.x,
// y: contentView.bounds.height,
// width: contentView.bounds.width,
// height: contentView.bounds.height)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//Public
public func showControls(progressValue:CGFloat) {
var progress = max(progressValue, 0)
progress = min(progress, 1)
self.contentView?.frame.origin.y = -controlsHeight * progress
self.contentView?.subviews.forEach {
if $0 != customView {
$0.alpha = 1 - progress
}
}
self.customView.frame.origin.y = contentView!.frame.origin.y + self.customView.frame.height + controlsHeight * progress
self.customView.alpha = progress
}
//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
self.customView.frame = .init(x: contentView!.frame.origin.x,
y: contentView!.frame.height,
width: contentView!.frame.width,
height: contentView!.frame.height)
self.controlsHeight = self.customView.frame.height
}
}
}
}
//
// DayControlsNavigatoinBar.swift
// 1Weather
//
// Created by Dmitry Stepanets on 12.03.2021.
//
import UIKit
class DayControlsNavigationBar: UINavigationBar {
private let customView = UIView()
private var contentView:UIView?
override init(frame: CGRect) {
super.init(frame: frame)
customView.backgroundColor = .red
}
override func layoutSubviews() {
super.layoutSubviews()
guard let contentView = self.contentView else {
self.findAndSetupContentView()
return
}
contentView.frame.origin.y = -30
customView.frame = .init(x: contentView.frame.origin.x,
y: contentView.bounds.height,
width: contentView.bounds.width,
height: contentView.bounds.height)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func findAndSetupContentView() {
subviews.forEach {
if String(cString: class_getName($0.classForCoder)) == "_UINavigationBarContentView" {
self.contentView = $0
self.contentView?.clipsToBounds = true
self.contentView?.addSubview(customView)
}
}
}
}
......@@ -20,6 +20,7 @@ private enum TodayCellType:Int, CaseIterable {
class TodayCellFactory {
public var onGetLocation:(() -> Location?)?
public var forecastPeriodCellFrame:CGRect = .zero
public var numberOfRows:Int {
return TodayCellType.allCases.count
}
......@@ -59,6 +60,7 @@ class TodayCellFactory {
return cell
case .forecastPeriod:
let cell = dequeueReusableCell(type: CityForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath)
forecastPeriodCellFrame = cell.frame
cell.configure(with: loc)
return cell
case .precipitation:
......
......@@ -13,6 +13,7 @@ class TodayViewController: UIViewController {
private let cityButton = NavigationCityButton()
private let viewModel:TodayViewModel
private let tableView = UITableView()
private var dayControlsNavigationBar:DayControlsNavigationBar?
private var localizationObserver:Any?
deinit {
......@@ -68,6 +69,8 @@ private extension TodayViewController {
}
func prepareNavigationBar() {
self.dayControlsNavigationBar = self.navigationController?.navigationBar as? DayControlsNavigationBar
//City button
cityButton.isHidden = true
cityButton.addTarget(self, action: #selector(handleCityButton), for: .touchUpInside)
......@@ -120,6 +123,24 @@ extension TodayViewController: UITableViewDataSource {
//MARK:- UITableView Delegate
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 startPointY = cellFrame.origin.y + cellFrame.height - controlsHeight
if scrollView.contentOffset.y >= startPointY {
let cellOffset = scrollView.contentOffset.y - startPointY
let progress = cellOffset / controlsHeight
dayControlsNavigationBar?.showControls(progressValue: progress)
print("progress: \(progress)")
}
else {
dayControlsNavigationBar?.showControls(progressValue: 0)
}
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
viewModel.todayCellFactory.willDisplay(cell: cell)
}
......
......@@ -21,7 +21,7 @@
<key>Cirque.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>6</integer>
<integer>4</integer>
</dict>
<key>Localize-Swift.xcscheme</key>
<dict>
......@@ -33,26 +33,26 @@
<key>Localize-Swift.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>6</integer>
</dict>
<key>Pods-1Weather.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<key>SnapKit.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
<integer>2</integer>
</dict>
<key>XMLCoder.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>6</integer>
<integer>5</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
......
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