Comments (2)
Hi @schmidan, I wrote this small wrapper which works well for me:
import AloeStackView
/// This class adds automatic scroll functionality when keyboard will show or hide.
open class AutoScrollStackViewController: AloeStackViewController {
// MARK: Properties
open var defaultContentInset: UIEdgeInsets = .zero {
didSet {
updateContentInset(with: defaultContentInset)
}
}
open var keyboardTopMargin: CGFloat = 20
// MARK: Lifecycle
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
addObservers()
}
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self)
}
// MARK: Keyboard Observers
@objc
open func keyboardWillShow(_ notification: Notification) {
let keyboardFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
guard var keyboardFrame = keyboardFrameValue?.cgRectValue else { return }
keyboardFrame = stackView.convert(keyboardFrame, from: nil)
let keyboardSize = keyboardFrame.size
let bottomInset = keyboardSize.height + keyboardTopMargin
let keyboardInset = UIEdgeInsets(
top: defaultContentInset.top,
left: defaultContentInset.left,
bottom: bottomInset,
right: defaultContentInset.right
)
updateContentInset(with: keyboardInset)
}
@objc
open func keyboardWillHide(_ notification: Notification) {
updateContentInset(with: defaultContentInset)
}
// MARK: Helpers
private func updateContentInset(with inset: UIEdgeInsets) {
stackView.contentInset = inset
stackView.scrollIndicatorInsets = inset
}
private func addObservers() {
let nc = NotificationCenter.default
nc.addObserver(
self, selector: #selector(keyboardWillShow(_:)),
name: UIResponder.keyboardWillShowNotification, object: nil
)
nc.addObserver(
self, selector: #selector(keyboardWillHide(_:)),
name: UIResponder.keyboardWillHideNotification, object: nil
)
}
}
Still not sure if something like this should be integrated into AloeStackViewController
though (since keyboard is not always needed), but it might be...
from aloestackview.
Thanks a bunch for the wrapper class. I have a similar solution but using composition.
i believe you are right and this should not be the responsibility of the stack view. as such, this issue can be closed
from aloestackview.
Related Issues (20)
- AloeStackViewController to support child UIViewControllers as a row HOT 3
- Improved touch and tap handling of cells HOT 1
- Swift 5 support HOT 3
- s.swift_version = '5.0' HOT 1
- Carthage build error with Xcode 11.0 beta 4 HOT 2
- Presenting in popover on iOS 13 displays with incorrect insets HOT 7
- Embedding TableView as row HOT 1
- [Feature suggestion] Paging
- [Feature Suggestion] willDisplay/endDisplay
- [Question] Access to the cell HOT 2
- No way to get the RowCount HOT 1
- RTL support on horizontal stack?
- Get access to UIStackview HOT 1
- Cannot build with `swift build`
- [Feature Suggestion] Reorder cells
- Scrolling always on?
- [question] Add stackView to container (with Storyboard)
- Problem when build on simulator, Xcode Version 12.0.1 (12A7300)
- SPM support?
- Is this library maintained? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aloestackview.