1 Star 0 Fork 0

Atlnads / KeyboardObserving

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

⌨️ Keyboard Observing

A Combine-based solution for observing and avoiding the keyboard in SwiftUI.

Swift Support Platform CocoaPods Compatible SwiftPM Compatible

Table of Contents

About

This package give you the ability to observe changes to keyboard state using the Keyboard ObservableObject type.

It also provides a KeyboardObservingView that adjusts its content to avoid the keyboard, and a .keyboardObserving() ViewModifier that adjusts the modified view to avoid the keyboard.

Demo

Requirements

  • iOS 13.0+
  • Xcode 11+
  • Swift 5.1+

Installation

This package can be installed using CocoaPods or Swift Package Manager.

CocoaPods

Add the following line to your Podfile:

pod 'KeyboardObserving'

For more information about how to get started with CocoaPods, check out the CocoaPods website.

Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(
        url: "https://github.com/nickffox/KeyboardObserving.git", 
        .branch:("master")
    )
]

If you're using SPM through Xcode:

  1. Go to File > Swift Packages > Add Package Dependency
  2. Enter https://github.com/nickffox/KeyboardObserving
  3. Select the branch option, and type "master"

For more information about how to get started with the Swift Package Manager, check out the Official SPM website or the SPM project on GitHub.

Usage

Using the KeyboardObserving ViewModifier

Add the .keyboardObserving() ViewModifier to your custom SwiftUI view.

import KeyboardObserving

struct YourView: View {

  var body: some View {
    VStack {
      // Your Content Here
    }
    .keyboardObserving()
  }
}

Using Keyboard and KeyboardObservingView

1. Add a Keyboard to your environment

In your SceneDelegate.swift file, add a Keyboard property, and add it to your scene's environment.

import KeyboardObserving

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

  var window: UIWindow?

  // A Keyboard that will be added to the environment.
  var keyboard = Keyboard()


  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    // Use a UIHostingController as window root view controller
    if let windowScene = scene as? UIWindowScene {
      let window = UIWindow(windowScene: windowScene)
      window.rootViewController = UIHostingController(
        rootView: YourRootView()
          // Adds the keyboard to the environment
          .environmentObject(keyboard)
      )
      self.window = window
      window.makeKeyAndVisible()
    }
  }
}
2. Create your View

Add your view's content inside of a KeyboardObservingView .

import KeyboardObserving

struct YourView: View {

  var body: some View {
    KeyboardObservingView {
      // Your content goes here!
    }
  }
}
MIT License Copyright (c) 2019 Nick Fox Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/atlnads/KeyboardObserving.git
git@gitee.com:atlnads/KeyboardObserving.git
atlnads
KeyboardObserving
KeyboardObserving
master

搜索帮助