SwiftScrollViews 1.1.0

SwiftScrollViews 1.1.0

RAJAMOHAN SADHU SUNDAR SINGH维护。




处理UITextField与UITextView跨键盘滚动至scroll view的简单方法。SwiftScrollViews框架是通过将UIScrollView添加扩展编写而成的。

Swift Scroll View Swift Table View Swift Collection View

特性

  • 对于overscroll至UIScrollView、UITableView和UICollectionView中的活动UITextFiedUITextView自动滚动。
  • 使用UITextFieldReturnKeyType设置分组。
  • 使用SwiftScrollViewDelegate在必要时,当分组中的最后UITextField完成编辑时执行动作。(参考SwiftScrollViewExample项目)。
  • 设置自定义的ReturnKeyType和键盘与活动UITextFieldUITextView之间的垂直空间。

要求

  • iOS 8.0+
  • Xcode 10.1+

安装

使用CocoaPods

pod 'SwiftScrollViews', '~>1.0' # Swift 4.2.1

手动安装

  1. 将项目中的 Source 文件夹下载并放置。
  2. 恭喜!

使用方法

基本设置

  1. 在 xib 或 storyboard 的 ViewController 中选择 scrollview。
  2. 前往 辅助编辑器/身份检查器/自定义类/类 并选择 SwiftScrollView。如果您有 UITableView,则使用 SwiftTableView,然后对于 UICollectionView 使用 SwiftCollectionView

SwiftScrollViewDelegate

该方法 func didEditingDone(for textField: UITextField) {}视图结束编辑 时执行。

当直接点击 ScrollViews 或点击键盘的返回按钮,如果 textField.returnKeyType != .default || textField.returnKeyType != .next 的时候,视图会结束编辑。

分组

通过在分组中最后一个字段的 textField.returnKeyType != .default || textField.returnKeyType != .next 来设置 一个视图中的 UITextFields 分组。

附加配置

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.

示例

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

贡献

我非常欢迎对 SwiftScrollViews 的贡献,有关更多信息,请查看 LICENSE 文件。

元信息

Rajamohan S – (https://rajamohan-s.github.io/)

在 MIT 许可证下分发。请查阅 LICENSE 文件以获取更多信息。