A simple approach to handle UITextField & UITextViews over scroll view accross keyboard. The SwiftScrollViews framework is written with the extension UIScrollView.
Features
- Auto scroll for actvie
UITextFiedandUITextViewoverUIScrollView,UITableViewandUICollectionView. - Set grouping by using
ReturnKeyTypeofUITextField. - Execute action when last
UITextFieldof the group did end editing if need by usingSwiftScrollViewDelegate. (ReferSwiftScrollViewExampleproject). - Set custom
ReturnKeyTypeand vertical space between keyboard and activeUITextFieldorUITextView.
Requirements
- iOS 8.0+
- Xcode 10.1+
Installation
Using Cocoapods
pod 'SwiftScrollViews', '~>1.0' # Swift 4.2.1Manually
- Download and drop
Sourcefolder in your project. - Congratulations!
Usage
The Basic Setup
- Select scrollview in xib or storyboard in viewcontroller.
- Go to Assistand Editor/Identity Inspector/Custom Class/Class as
SwiftScrollView. If you haveUITableViewthen useSwiftTableViewand thenSwiftCollectionViewforUICollectionView.
SwiftScrollViewDelegate
It is delegating the method func didEditingDone(for textField: UITextField) {} will exceute when view did end editing.
The view will end edit when directly taping the ScrollViews or Taping the keyboard return button if textField.returnKeyType != .default || textField.returnKeyType != .next.
Grouping
The group of UITextFields in a view by setting textField.returnKeyType != .default || textField.returnKeyType != .next at last field of that group.
Aditional Configuration
SwiftScrollViews.config.textComponentSpaceFromKeyboard = 40 //vertical space between keyboard and active text field or text view.
SwiftScrollViews.config.defaultDoneKey = .done // The default return key of last text field over the scroll view.Example:
class ScrollViewExample: UIViewController,SwiftScrollViewDelegate {
@IBOutlet weak var scrollView: SwiftScrollView!
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView.swiftScrollViewsDelegate = self
}
func didEditingDone(for textField: UITextField) {
//TODO:- Do further with by comparing textField with self.textField
let controller = UIAlertController(title: textField.placeholder ?? "Place Holder Nil", message: "✅ Editing Done!", preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "👍", style: .default, handler: nil))
self.present(controller, animated: true, completion: nil)
}
}Contribute
I would love you for the contribution to SwiftScrollViews, check the LICENSE file for more info.
Meta
Rajamohan S – (https://rajamohan-s.github.io/)
Distributed under the MIT license. See LICENSE for more information.



