Blogging in Lisp


Sizing An iOS Custom Keyboard for Scaled Apps

Submitted by Bill St. Clair on Fri, 05 Aug 2016 19:24:19 GMT

I've been writing a custom iOS keyboard for Learning Touch, a novel way of entering text that we're hoping will be easier for people with non-steady hands, though it works fine for the rest of us, too. Can't give any more details until the patent request has been filed, but that will be soon.

I lay out the keyboard myself, with sizes designed to work on a standard 768x1024 pixel iPad, and scaled to the screen size of the device on which it's running. This works fine, for apps that have been updated for each device's screen size, but it failed for old apps that were scaled and/or run in letterbox mode; the keyboard was too wide, so part of it was invisible off the right edge of the screen.

I was just using the hardware bounds, in logical pixels. I needed to scale to the view size, which is narrower for scaled apps. The simple (Swift) code below takes the hardware size from UIScreen.mainScreen.bounds.size and the parent view size (that view is set outside this function and referenced with the getParentView() call).

Strangely, I found no hint of this algorithm in a bunch of Google searches, so I'm posting it, to hopefully make it easier for the next guy to find.

    public static func screenSize() -> CGSize {
        var size = UIScreen.mainScreen().bounds.size
        if let parent = getParentView() {
            // Accomodate for old apps that need to be scaled.
            let vw = parent.frame.width
            let factor = vw / size.width
            size.width = vw
            size.height *= factor
        return size

Unfortunately, there doesn't appear to be any way to tell if an app is running in letterbox mode, so you'll tend to size the keyboard vertically bigger than ideal for those.

Add comment   Edit post   Add post

Previous Posts:

Conway's Life in JavaScript
Mac OS X 10.11.4 Beachball on Wake from Sleep
Google Authenticator, in Your Web Browser
Another Old Friend
Firefox Discontinuing Tab Groups
Barlow's Declaration Turns Twenty
Hello Again Old Friend
Mail-in-a-Box Rocks!!
ReadErl Is Live
Audio Hijack 3