Commit 5f7e1893 by Dmitriy Stepanets

Added custom navigation bar

parent 89598404
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
CDE18DCD25D1666700C80ED9 /* ForecastCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */; }; CDE18DCD25D1666700C80ED9 /* ForecastCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */; };
CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; }; CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; };
CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */; }; CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */; };
CDEABC5925FEA13E00B0F6C1 /* DayControlsNavigatoinController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDEABC5825FEA13E00B0F6C1 /* DayControlsNavigatoinController.swift */; };
CDEE8AD725DA882200C289DE /* ForecastPeriodButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDEE8AD625DA882200C289DE /* ForecastPeriodButton.swift */; }; CDEE8AD725DA882200C289DE /* ForecastPeriodButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDEE8AD625DA882200C289DE /* ForecastPeriodButton.swift */; };
CE578FD325F7E89400E8B85D /* DayTimeWeather.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FD225F7E89400E8B85D /* DayTimeWeather.swift */; }; CE578FD325F7E89400E8B85D /* DayTimeWeather.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FD225F7E89400E8B85D /* DayTimeWeather.swift */; };
CE9D181625ECB8370028D9D7 /* MulticastDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9D181525ECB8370028D9D7 /* MulticastDelegate.swift */; }; CE9D181625ECB8370028D9D7 /* MulticastDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9D181525ECB8370028D9D7 /* MulticastDelegate.swift */; };
...@@ -160,6 +161,7 @@ ...@@ -160,6 +161,7 @@
CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastCoordinator.swift; sourceTree = "<group>"; }; CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastCoordinator.swift; sourceTree = "<group>"; };
CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; }; CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; };
CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCityButton.swift; sourceTree = "<group>"; }; CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCityButton.swift; sourceTree = "<group>"; };
CDEABC5825FEA13E00B0F6C1 /* DayControlsNavigatoinController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayControlsNavigatoinController.swift; sourceTree = "<group>"; };
CDEE8AD625DA882200C289DE /* ForecastPeriodButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastPeriodButton.swift; sourceTree = "<group>"; }; CDEE8AD625DA882200C289DE /* ForecastPeriodButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastPeriodButton.swift; sourceTree = "<group>"; };
CE578FD225F7E89400E8B85D /* DayTimeWeather.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayTimeWeather.swift; sourceTree = "<group>"; }; CE578FD225F7E89400E8B85D /* DayTimeWeather.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayTimeWeather.swift; sourceTree = "<group>"; };
CE9D181525ECB8370028D9D7 /* MulticastDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulticastDelegate.swift; sourceTree = "<group>"; }; CE9D181525ECB8370028D9D7 /* MulticastDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulticastDelegate.swift; sourceTree = "<group>"; };
...@@ -461,6 +463,7 @@ ...@@ -461,6 +463,7 @@
CD9B6B1025DBC723001D9B80 /* CubicCurveAlgorithm.swift */, CD9B6B1025DBC723001D9B80 /* CubicCurveAlgorithm.swift */,
CD86246B25E6826A0097F3FB /* InnerShadowLayer.swift */, CD86246B25E6826A0097F3FB /* InnerShadowLayer.swift */,
CD8343B825FBEFF60003101F /* DayControlsNavigationBar.swift */, CD8343B825FBEFF60003101F /* DayControlsNavigationBar.swift */,
CDEABC5825FEA13E00B0F6C1 /* DayControlsNavigatoinController.swift */,
); );
path = Helpers; path = Helpers;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -698,6 +701,7 @@ ...@@ -698,6 +701,7 @@
CD9B6B1425DBCDE2001D9B80 /* GraphView.swift in Sources */, CD9B6B1425DBCDE2001D9B80 /* GraphView.swift in Sources */,
CD39F2EE25DE858D009FE398 /* NotificationName+Localization.swift in Sources */, CD39F2EE25DE858D009FE398 /* NotificationName+Localization.swift in Sources */,
CEAFF08F25DFC6ED00DF4EBF /* HourlyWeather.swift in Sources */, CEAFF08F25DFC6ED00DF4EBF /* HourlyWeather.swift in Sources */,
CDEABC5925FEA13E00B0F6C1 /* DayControlsNavigatoinController.swift in Sources */,
CD71709025FA317700A63C27 /* ForecastTimePeriodView.swift in Sources */, CD71709025FA317700A63C27 /* ForecastTimePeriodView.swift in Sources */,
CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */, CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */,
CD17C60225D15C8500EE884E /* CoordinatorProtocol.swift in Sources */, CD17C60225D15C8500EE884E /* CoordinatorProtocol.swift in Sources */,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<key>1Weather.xcscheme_^#shared#^_</key> <key>1Weather.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>6</integer>
</dict> </dict>
<key>PG (Playground) 1.xcscheme</key> <key>PG (Playground) 1.xcscheme</key>
<dict> <dict>
......
...@@ -10,7 +10,7 @@ import UIKit ...@@ -10,7 +10,7 @@ import UIKit
class TodayCoordinator:Coordinator { class TodayCoordinator:Coordinator {
//Private //Private
private let todayViewModel = TodayViewModel(locationManager: LocationManager.shared) // TODO: get rid of singleton maybe? private let todayViewModel = TodayViewModel(locationManager: LocationManager.shared) // TODO: get rid of singleton maybe?
private let navigationController = UINavigationController(navigationBarClass: DayControlsNavigationBar.self, toolbarClass: nil) private let navigationController = DayControlsNavigatoinController()
private var tabBarController:UITabBarController? private var tabBarController:UITabBarController?
//Public //Public
......
...@@ -10,6 +10,8 @@ import UIKit ...@@ -10,6 +10,8 @@ import UIKit
class DayControlsNavigationBar: UINavigationBar { class DayControlsNavigationBar: UINavigationBar {
private let customView = UIView() private let customView = UIView()
private var contentView:UIView? private var contentView:UIView?
private var currentProgress:CGFloat = 0
private var savedProgress:CGFloat = 0
var controlsHeight:CGFloat = 0 var controlsHeight:CGFloat = 0
override init(frame: CGRect) { override init(frame: CGRect) {
...@@ -21,30 +23,31 @@ class DayControlsNavigationBar: UINavigationBar { ...@@ -21,30 +23,31 @@ class DayControlsNavigationBar: UINavigationBar {
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if contentView == nil { guard let contentView = self.contentView else {
self.findAndSetupContentView() self.findAndSetupContentView()
return
} }
// guard let contentView = self.contentView else { print("Layout subviews")
// self.findAndSetupContentView() let targetHeight = contentView.frame.height * 2
// return self.contentView?.frame.size.height = targetHeight
// }
// contentView.frame.origin.y = -30 self.customView.frame = .init(x: contentView.frame.origin.x,
// customView.frame = .init(x: contentView.frame.origin.x, y: targetHeight / 2,
// y: contentView.bounds.height, width: contentView.frame.width,
// width: contentView.bounds.width, height: targetHeight / 2)
// height: contentView.bounds.height) self.controlsHeight = targetHeight / 2
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
//Public //Public
public func showControls(progressValue:CGFloat) { public func showControls(progressValue:CGFloat) {
var progress = max(progressValue, 0) var progress = max(progressValue, 0)
progress = min(progress, 1) progress = min(progress, 1)
self.currentProgress = progress
self.contentView?.frame.origin.y = -controlsHeight * progress self.contentView?.frame.origin.y = -controlsHeight * progress
self.contentView?.subviews.forEach { self.contentView?.subviews.forEach {
...@@ -53,10 +56,19 @@ class DayControlsNavigationBar: UINavigationBar { ...@@ -53,10 +56,19 @@ class DayControlsNavigationBar: UINavigationBar {
} }
} }
self.customView.frame.origin.y = contentView!.frame.origin.y + self.customView.frame.height + controlsHeight * progress
self.customView.alpha = progress self.customView.alpha = progress
} }
public func saveProgress() {
savedProgress = currentProgress
}
public func restoreProgress() {
currentProgress = savedProgress
showControls(progressValue: currentProgress)
savedProgress = 0
}
//Private //Private
private func findAndSetupContentView() { private func findAndSetupContentView() {
subviews.forEach { subviews.forEach {
...@@ -66,12 +78,6 @@ class DayControlsNavigationBar: UINavigationBar { ...@@ -66,12 +78,6 @@ class DayControlsNavigationBar: UINavigationBar {
self.contentView?.addSubview(customView) self.contentView?.addSubview(customView)
self.customView.alpha = 0 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
} }
} }
} }
......
//
// DayControlsNavigatoinController.swift
// 1Weather
//
// Created by Dmitry Stepanets on 15.03.2021.
//
import UIKit
class DayControlsNavigatoinController: UINavigationController {
private var dayControllsNavBar:DayControlsNavigationBar? {
return self.navigationBar as? DayControlsNavigationBar
}
init() {
super.init(navigationBarClass: DayControlsNavigationBar.self, toolbarClass: nil)
delegate = self
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func popViewController(animated: Bool) -> UIViewController? {
let popViewController = super.popViewController(animated: animated)
dayControllsNavBar?.restoreProgress()
// transitionCoordinator?.animate(alongsideTransition: nil, completion: {[weak self] _ in
// self?.dayControllsNavBar?.restoreProgress()
// })
return popViewController
}
}
extension DayControlsNavigatoinController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
// if viewController === viewControllers.first {
// self.dayControllsNavBar?.restoreProgress()
// }
}
func navigationController(_ navigationController: UINavigationController,
willShow viewController: UIViewController,
animated: Bool)
{
if viewController != self.viewControllers.first {
self.dayControllsNavBar?.saveProgress()
self.dayControllsNavBar?.showControls(progressValue: 0)
}
}
}
...@@ -41,7 +41,7 @@ class TodayViewController: UIViewController { ...@@ -41,7 +41,7 @@ class TodayViewController: UIViewController {
viewModel.delegate = self viewModel.delegate = self
viewModel.updateWeather() viewModel.updateWeather()
} }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
...@@ -123,6 +123,12 @@ extension TodayViewController: UITableViewDataSource { ...@@ -123,6 +123,12 @@ extension TodayViewController: UITableViewDataSource {
//MARK:- UITableView Delegate //MARK:- UITableView Delegate
extension TodayViewController: UITableViewDelegate { extension TodayViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = UIViewController()
vc.view.backgroundColor = .red
navigationController?.pushViewController(vc, animated: true)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) { func scrollViewDidScroll(_ scrollView: UIScrollView) {
let cellFrame = viewModel.todayCellFactory.forecastPeriodCellFrame let cellFrame = viewModel.todayCellFactory.forecastPeriodCellFrame
guard cellFrame.origin.y > 0 else { return } guard cellFrame.origin.y > 0 else { return }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<key>Cirque.xcscheme_^#shared#^_</key> <key>Cirque.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>4</integer> <integer>5</integer>
</dict> </dict>
<key>Localize-Swift.xcscheme</key> <key>Localize-Swift.xcscheme</key>
<dict> <dict>
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<key>Localize-Swift.xcscheme_^#shared#^_</key> <key>Localize-Swift.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>6</integer> <integer>4</integer>
</dict> </dict>
<key>Pods-1Weather.xcscheme</key> <key>Pods-1Weather.xcscheme</key>
<dict> <dict>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<key>XMLCoder.xcscheme_^#shared#^_</key> <key>XMLCoder.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>5</integer> <integer>3</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <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