diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f572ff..66f08e8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### 1.3.0 +- **Add**: `HeaderTransitionDelegate` - Helper for transition of TableView header and navigationBar title view + ### 1.2.0 - **Add**: `TIKeychainUtils` - Set of helpers for Keychain classes. diff --git a/LeadKit.podspec b/LeadKit.podspec index 6a9a6f1f..066922d1 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "1.2.0" + s.version = "1.3.0" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/TIFoundationUtils/TIFoundationUtils.podspec b/TIFoundationUtils/TIFoundationUtils.podspec index bf875d6d..668c1b50 100644 --- a/TIFoundationUtils/TIFoundationUtils.podspec +++ b/TIFoundationUtils/TIFoundationUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIFoundationUtils' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Set of helpers for Foundation framework classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIKeychainUtils/TIKeychainUtils.podspec b/TIKeychainUtils/TIKeychainUtils.podspec index 789ee1a4..86cb69f4 100644 --- a/TIKeychainUtils/TIKeychainUtils.podspec +++ b/TIKeychainUtils/TIKeychainUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIKeychainUtils' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Set of helpers for Keychain classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TISwiftUtils/TISwiftUtils.podspec b/TISwiftUtils/TISwiftUtils.podspec index 9e67d72c..4bb0e81b 100644 --- a/TISwiftUtils/TISwiftUtils.podspec +++ b/TISwiftUtils/TISwiftUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TISwiftUtils' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Bunch of useful helpers for Swift development.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TITableKitUtils/TITableKitUtils.podspec b/TITableKitUtils/TITableKitUtils.podspec index 8a954ccd..29a808ab 100644 --- a/TITableKitUtils/TITableKitUtils.podspec +++ b/TITableKitUtils/TITableKitUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TITableKitUtils' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Set of helpers for TableKit classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TITransitions/TITransitions.podspec b/TITransitions/TITransitions.podspec index 51af6e08..f61fd5d5 100644 --- a/TITransitions/TITransitions.podspec +++ b/TITransitions/TITransitions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TITransitions' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Set of custom transitions to present controller. ' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIUIElements/Assets/first_header_transition_exemple.gif b/TIUIElements/Assets/first_header_transition_exemple.gif new file mode 100644 index 00000000..69f3606f Binary files /dev/null and b/TIUIElements/Assets/first_header_transition_exemple.gif differ diff --git a/TIUIElements/Assets/licard_header_transition_exemple.gif b/TIUIElements/Assets/licard_header_transition_exemple.gif new file mode 100644 index 00000000..e7747ace Binary files /dev/null and b/TIUIElements/Assets/licard_header_transition_exemple.gif differ diff --git a/TIUIElements/README.md b/TIUIElements/README.md index 68d1da24..8b47e07e 100644 --- a/TIUIElements/README.md +++ b/TIUIElements/README.md @@ -4,6 +4,55 @@ Bunch of useful protocols and views: - `RefreshControl` - a basic UIRefreshControl with fixed refresh action. +# HeaderTransitionDelegate +Use for transition table header to navigationBar view while scrolling + +## Your class must implement the HeaderViewHandlerProtocol protocol +```swift +public protocol HeaderViewHandlerProtocol: UIViewController { + var largeHeaderView: UIView? { get } + var headerView: UIView? { get } + var tableView: UITableView { get } +} +``` + +## Usage if your ViewController don't needs extend UITableViewDelegate +```swift +let headerTransitionDelegate = HeaderTransitionDelegate(headerViewHandler: self) +tableView.delegate = headerTransitionDelegate +``` + +## Usage if your ViewController needs extend UITableViewDelegate +```swift +let headerTransitionDelegate = HeaderTransitionDelegate(headerViewHandler: self) +tableView.delegate = self +. +. +func scrollViewDidScroll(_ scrollView: UIScrollView) { + headerTransitionDelegate?.scrollViewDidScrollHandler(scrollView) + + /// Your local work +} +``` + + + + + + + + +
+

+ +

+
+

+ +

+
+ + # Installation via SPM -You can install this framework as a target of LeadKit. +You can install this framework as a target of LeadKit. \ No newline at end of file diff --git a/TIUIElements/Sources/Helpers/HeaderTransitionDelegate.swift b/TIUIElements/Sources/Helpers/HeaderTransitionDelegate.swift new file mode 100644 index 00000000..96f132aa --- /dev/null +++ b/TIUIElements/Sources/Helpers/HeaderTransitionDelegate.swift @@ -0,0 +1,67 @@ +import Foundation +import UIKit + +public protocol HeaderViewHandlerProtocol: UIViewController { + var largeHeaderView: UIView? { get } + var headerView: UIView? { get } + var tableView: UITableView { get } +} + +open class HeaderTransitionDelegate: NSObject { + + private var navigationBarHeight: CGFloat = 0 + private var startOffset: CGFloat = 0 + private var statusBarHeight: CGFloat = 0 + private var isStartSet = true + + private weak var headerViewHandler: HeaderViewHandlerProtocol? + + public init(headerViewHandler: HeaderViewHandlerProtocol) { + self.headerViewHandler = headerViewHandler + super.init() + + initialUpdateHeaderView() + } + + private func initialUpdateHeaderView() { + headerViewHandler?.navigationController?.navigationBar.topItem?.titleView = headerViewHandler?.headerView + headerViewHandler?.navigationController?.navigationBar.topItem?.titleView?.isHidden = true + + headerViewHandler?.tableView.tableHeaderView = headerViewHandler?.largeHeaderView + + headerViewHandler?.tableView.delegate = self + } +} + +extension HeaderTransitionDelegate: UITableViewDelegate { + open func scrollViewDidScrollHandler(_ scrollView: UIScrollView) { + guard let headerHandler = headerViewHandler, + let largeHeaderView = headerHandler.largeHeaderView else { + headerViewHandler?.navigationController?.navigationBar.topItem?.titleView?.isHidden = false + return + } + + if isStartSet { + startOffset = -(headerHandler.tableView.contentOffset.y) + startOffset = startOffset < 0 ? 0 : startOffset + navigationBarHeight = headerHandler.navigationController?.navigationBar.bounds.height ?? 0 + if #available(iOS 13.0, *) { + statusBarHeight = headerHandler.view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0 + } else { + statusBarHeight = UIApplication.shared.statusBarFrame.height + } + isStartSet = false + } + + let prefersLargeTitles = headerHandler.navigationController?.navigationBar.prefersLargeTitles ?? false + let offsetY = scrollView.contentOffset.y + startOffset + let navigayionBarOffset = prefersLargeTitles ? navigationBarHeight - statusBarHeight : 0 + let isHidden = offsetY <= (largeHeaderView.frame.height + navigayionBarOffset) + headerHandler.navigationController?.navigationBar.topItem?.titleView?.isHidden = isHidden + } + + + public func scrollViewDidScroll(_ scrollView: UIScrollView) { + scrollViewDidScrollHandler(scrollView) + } +} diff --git a/TIUIElements/TIUIElements.podspec b/TIUIElements/TIUIElements.podspec index 0ee0b3db..3bd1d878 100644 --- a/TIUIElements/TIUIElements.podspec +++ b/TIUIElements/TIUIElements.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIUIElements' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Bunch of useful protocols and views.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIUIKitCore/TIUIKitCore.podspec b/TIUIKitCore/TIUIKitCore.podspec index 9d482c7b..51659e94 100644 --- a/TIUIKitCore/TIUIKitCore.podspec +++ b/TIUIKitCore/TIUIKitCore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIUIKitCore' - s.version = '1.2.0' + s.version = '1.3.0' s.summary = 'Core UI elements: protocols, views and helpers.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' }