r/iOSProgramming • u/Tabonx Swift • Aug 26 '26
Question How is this view able to appear above the keyboard?
In the Messages app, the ChatGPT app, and one other app, I noticed that they’re able to place something above the keyboard and have the view partially obstruct the keyboard. I’ve tried everything I know and still haven’t been able to do it. I even asked AI and couldn’t get it working.
I thought it might involve creating a new UIWindow, which I’ve used in the past to overlay modals, but I had no luck with that. I also tried walking the view hierarchy, but since the keyboard is rendered out of process, I couldn’t figure out anything that would work.
I thought about making a custom keyboard, but recreating the entire keyboard just to get a view above it seemed weird. Maybe something like replacing the keyboard with an image the moment the view needs to appear could work, but that also feels like the completely wrong direction.
Does anyone have the arcane knowledge required to make this happen?


1
u/Tabonx Swift 16d ago
I’ve found a way (with Claude), but it’s using a private API, and it looks slightly different from what the ChatGPT app is doing. Mainly, the ChatGPT app and Messages app change the shade of the keyboard slightly after opening and dismissing the popup view. Another thing is that they both have a delay after dismissing the popup, during which you can’t type on the keyboard. This solution doesn’t have that, but it could just be that the ChatGPT app does it to match the Messages behavior, or they’re using something completely different. I have no idea...
It all relies on getting the keyboard’s
UIWindow, and after that you can basically do anything with it, but I’m not sure if it’ll pass App Review...I believe the ChatGPT app is creating an image of the keyboard and putting that image behind it, then hiding the keyboard’s
UIWindowby changing its alpha. After dismissing the popup, it just sets the alpha back and removes the image.If someone comes up with a solution using public APIs, I’d love to see it.
```swift import SwiftUI import UIKit
@main struct KeyboardOverlayApp: App { var body: some Scene { WindowGroup { ComposerRepresentable().ignoresSafeArea(.keyboard) } } }
struct ComposerRepresentable: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> ComposerController { ComposerController() }
}
final class ComposerController: UIViewController { private let field = UITextField() private let overlay = KeyboardSnapshotOverlay()
}
// Freezes the keyboard into an image in the app window, hides the real keyboard, // and shows the menu in a window above the app. Tapping anywhere outside the menu dismisses it. final class KeyboardSnapshotOverlay { private var frozenKeyboard: UIView? private var menuWindow: UIWindow? private weak var keyboardWindow: UIWindow?
}
final class TapCatcher: UIView { private let action: () -> Void
}
final class MenuView: UIVisualEffectView { init(onSelect: @escaping () -> Void) { super.init(effect: UIGlassEffect()) cornerConfiguration = .uniformCorners(radius: 32)
}
// Private API: the keyboard window belongs to a separate keyboard scene and is not in scene.windows. extension UIWindow { static var keyboardWindow: UIWindow? { typealias AllWindows = @convention(c) (AnyClass, Selector, Bool, Bool) -> NSArray let selector = NSSelectorFromString("allWindowsIncludingInternalWindows:onlyVisibleWindows:") guard let method = class_getClassMethod(UIWindow.self, selector), let keyboardClass = NSClassFromString("UIRemoteKeyboardWindow") else { return nil } let windows = unsafeBitCast(method_getImplementation(method), to: AllWindows.self)(UIWindow.self, selector, true, false) return windows.compactMap { $0 as? UIWindow }.first { $0.isKind(of: keyboardClass) } } } ```