feat: Add HeaderTransitionDelegate - Helper for transition of TableView header and navigationBar title view

This commit is contained in:
Boyko Mihail 2021-06-03 18:41:27 +03:00
parent 954080891d
commit 2de6bc2df3
13 changed files with 128 additions and 9 deletions

View File

@ -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.

View File

@ -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"

View File

@ -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' }

View File

@ -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' }

View File

@ -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' }

View File

@ -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' }

View File

@ -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' }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

View File

@ -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
}
```
<table border="0" cellspacing="30" cellpadding="30">
<tbody>
<tr>
<td>
<p align="left">
<img src="Assets/first_header_transition_exemple.gif" width=300 height=600>
</p>
</td>
<td>
<p align="rigth">
<img src="Assets/licard_header_transition_exemple.gif" width=300 height=600>
</p>
</td>
</tr>
</tbody>
</table>
# Installation via SPM
You can install this framework as a target of LeadKit.
You can install this framework as a target of LeadKit.

View File

@ -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)
}
}

View File

@ -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' }

View File

@ -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' }