https://github.com/blinksh/kb-layout-issue-demo-app
https://github.com/blinksh/kb-layout-issue-demo-app
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/blinksh/kb-layout-issue-demo-app
- Owner: blinksh
- Created: 2022-08-03T09:19:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-03T15:17:46.000Z (almost 4 years ago)
- Last Synced: 2025-05-20T17:16:24.078Z (about 1 year ago)
- Language: Objective-C
- Size: 643 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multi-window KB Layout Issues
## NSNotificationCenter
If application in app delegate (`application:didFinishLaunchingWithOptions:`) subscribes to `UIKeyboardDidChangeFrameNotification`.
```objc
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_kbFrameChanged:) name:UIKeyboardDidChangeFrameNotification object:nil];
```
In `_kbFrameChanged` there is no way to detect for what window (UIWindowScene) coordinates `UIKeyboardFrameEndUserInfoKey` frame is.
So there is no way to proper calculate screen coordinates for keyboard.
Note: This is only occurs when app has 2 or more UIWindowScenes on the screen.
Posible solution: Add `UIScreenKeyboardFrameEndUserInfoKey`
## UIKeyboardLayoutGuide
We suspect that TrackingLayoutGuide for keyboard also uses `UIKeyboardDidChangeFrameNotification` and it is also affected by this issue.
On following screenshot is example of this app. 2 and 3 windows are separate window scenes. Red view is constrained with `UIKeyboardLayoutGuide`.

```objc
[[_kbTrackerView.leadingAnchor constraintEqualToAnchor:self.view.keyboardLayoutGuide.leadingAnchor] setActive:YES];
[[_kbTrackerView.widthAnchor constraintEqualToAnchor: self.view.keyboardLayoutGuide.widthAnchor] setActive:YES];
[[_kbTrackerView.heightAnchor constraintEqualToAnchor: self.view.keyboardLayoutGuide.heightAnchor] setActive:YES];
[[_kbTrackerView.bottomAnchor constraintEqualToAnchor:self.view.keyboardLayoutGuide.bottomAnchor] setActive:YES];
self.view.keyboardLayoutGuide.followsUndockedKeyboard = YES;
```
And layout system also confuses between windows and apply wrong constrains to `_kbTrackerView` (red view).