Giter VIP home page Giter VIP logo

keyboardlayoutguide's Introduction

⌨️ KeyboardLayoutGuide

Apple's missing KeyboardLayoutGuide

Language: Swift 5 Platform: iOS 9+ SPM compatible Build Status codebeat badge License: MIT GitHub tag

  • No Subclassing / Protocol inheritance / obscure overrides
  • No more keyboard notification handling
  • UIKit Friendly
  • Takes safeArea into account
  • Only animates if view is fully on screen

How to use it

Simply constrain your views to the KeyboardLayoutGuide's top anchor the way you would do natively:

override func viewDidLoad() {
    super.viewDidLoad()

    // Pin your button to the keyboard
    button.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor).isActive = true
}

Bonus: if you're using Stevia, this gets even more concise \o/

button.Bottom == view.keyboardLayoutGuide.Top

If you add your view in Interface Builder, don't forget to enable the "Remove at build time" checkbox for the bottom constraint:

Safe Area

By default, KeyboardLayoutGuide will align your item with the bottom safe area. This is a behaviour that can be opt out by using keyboardLayoutGuideNoSafeArea instead of keyboardLayoutGuide.

Installation

The Swift Package Manager (SPM) is now the official way to install KeyboardLayoutGuide. The other package managers are now deprecated as of 1.7.0 and won't be supported in future versions.

Swift Package Manager

Xcode > File > Swift Packages > Add Package Dependency... > Paste https://github.com/freshOS/KeyboardLayoutGuide

CocoaPods - Deprecated

To install KeyboardLayoutGuide via CocoaPods, add the following line to your Podfile:

target 'MyAppName' do
  pod 'Keyboard+LayoutGuide'
  use_frameworks!
end

Carthage - Deprecated

To install KeyboardLayoutGuide via Carthage, add the following line to your Cartfile:

github "freshos/KeyboardLayoutGuide"

Manually

Just add Keyboard+LayoutGuide.swift to your Xcode project.

License

KeyboardLayoutGuide is available under the MIT license. See the LICENSE file for more info.

keyboardlayoutguide's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keyboardlayoutguide's Issues

Better API for using safe area

This is a very handy framework!

Currently keyboardLayoutGuide automatically pins to safeAreaLayoutGuide.bottom.
There is a way to disable it getting a pointer to keyboardLayoutGuide and setting its usesSafeArea property to usesSafeArea.

Issue

There are two cases:

  1. Currently you can't pin two existing views to the keyboardLayoutGuide, one taking safeArea into account, the second doesn't — keyboardLayoutGuide is a single instance property.
  2. It's not very comfy. You should write something like:
let keyboardLayoutGuide = view.keyboardLayoutGuide // we don't know about the implementation, so we're holding a reference here
keyboardLayoutGuide.usesSafeArea = false
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true

Solution

I prefer one from the following:

  1. having a separate property for keyboardLayoutGuide with usesSafeArea = false
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuideNoSafeArea.topAnchor).isActive = true
  1. having a computed property returning KeyboardLayoutGuide with usesSafeArea turned off
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.noSafeArea.topAnchor).isActive = true

Achievable via extension like:

public extension KeyboardLayoutGuide {
    var noSafeArea: KeyboardLayoutGuide {
        self.usesSafeArea = false
        return self
    }
}

Provide option to use safe area or not

Currently, if the device is running iOS 11 or newer, the keyboardLayoutGuide.bottomAnchor is always equal to the view's safeAreaLayoutGuide.bottomAnchor.

Sometimes it is nice to be able to pin views to the bottom of the screen, instead of the bottom of the safe area. It would be nice if there was a setting or parameter for determining whether or not the keyboardLayoutGuide uses the safe area.

Extraneous space between view and keyboard

Nice library!

I have an issue though. There is extra space like shown:

Screen Shot 2019-10-22 at 2 10 46 PM

I'm using it like this (inside NSLayoutConstraint.activate([]))
accessoryView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor)

issue with iphone 5s when testing!!

I have issue in height initial the app in the chat

view.inputViewContainer.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true

image

Regards!!

Weird animation when the first responder is a secured textfield.

Hello,

First of all congrats for the lightweight and great implementation. It's the best i've seen so far.
There is a bug where when switching the first responder from a normal textfield to a secured textfield, a weird animation is performed. This is cause because for some reason the keyboardWillChangeFrame notification is called not once but three times, the first one being a weird value. In order to fix this, we just have to perform the change animated only when the duration specified in the notification is greater than 0.

Here is a screen recording of the bug: https://my.pcloud.com/publink/show?code=XZO6ibkZ92g9nOy76gbtm7VTohGNg0GDcq27

SnapKit - Animations does not work.

Hi. I have been using this library for every project I have worked on. Never really had a problem. However this last project we decided using SnapKit.

I have set this button to be aligned with the keyboard. Button does change its position when the keyboard is opened or closed but not along with the keyboard. It just changes its frame at a moment.

Does anyone have any suggestions?

Wrong guide position when keyboard doesn't intersect view

There are cases, when keyboard doesn't intersect view controller's view: e.g. view controller is shown modally with modalPresentationStyle == .formSheet on iPad, however keyboardLayoutGuide is shrinked by the height of the keyboard.

Bringing back Cocoapods/Carthage support

Hi,
firstly, thanks for great library!
I have one question - is it possible to bring back support for other dependency managers? SPM is great and all, but it is not yet suitable for all use cases (e.g. libraries with mixed Swift/Obj-C or with resources). Because of that, lots of projects can't switch to it yet and potentially having two dependency managers (e.g. Cocoapods + SPM) might do more harm than good (e.g. resolving some subdependencies) and confuse other developers.

If that's not something you want to do, then I think it would be good idea to remove Carthage and Cocoapods badges from README

Xcode 13 beta 3 - SwiftPM - Build error: UIApplication.shared not available in iOS App Extension

When building an app with KeyboardLayoutGuide from Swift Package Manager in Xcode 13 beta 3 that does not use app extensions, compiler errors related to API availability in app extensions are emitted.

Reproduction Steps

  • Create a new iOS project in Xcode 13 beta 3
  • Add KeyboardLayoutGuide at latest version (1.7.0) using Swift Package Manager
  • Build the app

Result: multiple errors on UIApplication.shared usage:

'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.

Other Notes

This appears to be expected behavior in Xcode 13 beta 3 with Swift Package Manager, based on this Apple Developer Forums thread and this Swift forums post. The Apple engineer in the second link recommends dealing with this by marking declarations as unavailable to app extensions when they use APIs that are unavailable to app extensions.


Update: It looks like the Swift team is reconsidering how this behaves. I'll update this issue as we hear more from them.

Adding safe area to the keyboard layout guide

Great idea for a library.

It works great with the exception that it seems to add an extra safe area to the height of the guide when the keyboard is opened. I think it's because the height in the keyboard notification event takes the safe area into account. Am I understanding safe area wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.