archagon / tasty-imitation-keyboard

A custom keyboard for iOS8 that serves as a tasty imitation of the default Apple keyboard. Built using Swift and the latest Apple technologies!
BSD 3-Clause "New" or "Revised" License
1.2k stars 290 forks source link

How to change between two keyboards? #96

Open mikrosk opened 8 years ago

mikrosk commented 8 years ago

I was very kindly surprised how universal processing of the Keyboard class is. I can define my own layout, my custom types, with all the colours, letters, images, amazing.

I've been wondering, is there a way how to switch between them? From what I've seen it seems the controller initializes the layout only once and then just hides/shows the default settings, if needed.

I haven't done much experiments with it yet but if you can give me some hints, I'll appreciate that. :)

Keep up the great work!

simoncorstonoliver commented 8 years ago

I've done some work allowing the user to flip between layouts: https://github.com/polishedcode/tasty-imitation-keyboard

mikrosk commented 8 years ago

That's great stuff, mate! However, I'm experiencing much more unstable behaviour with your version, esp. when I start it in the simulator (iOS 9.3) -- many times I'm unable to switch back to the original keyboard, I mean literally the globe button does nothing, I have to restart the simulator in some cases. As soon as I try the original code, it works fine.

simoncorstonoliver commented 8 years ago

Yeah the behavior of the switching a bit twitchy. You have to long press the globe button and slide along to the pop up. Tapping on the button is a bit unreliable.

On Mon, Jun 20, 2016 at 4:32 PM, Miro Kropacek notifications@github.com wrote:

That's great stuff, mate! However, I'm experiencing much more unstable behaviour with your version, esp. when I start it in the simulator (iOS 9.3) -- many times I'm unable to switch back to the original keyboard, I mean literally the globe button does nothing, I have to restart the simulator in some cases. As soon as I try the original code, it works fine.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/archagon/tasty-imitation-keyboard/issues/96#issuecomment-227300456, or mute the thread https://github.com/notifications/unsubscribe/ALQ5GclomyEGQ2ksaRrxmvnHvnFCeghzks5qNyL2gaJpZM4I0_Sc .

mikrosk commented 8 years ago

Any idea what's causing it or better, any hope of fixing it? For me, this is a showstopper, even though I love the other features :-( (I'm still a beginner in iOS/Swift).

dawand commented 8 years ago

You can add keyView.addTarget(self, action: #selector(KeyboardViewController.advanceTapped), forControlEvents: .TouchUpInside) under case Key.KeyType.KeyboardChange: in KeyboardViewController

simoncorstonoliver commented 8 years ago

Added single tap handler per Dawand@'s comment. Give that a try mikrosk@.

https://github.com/polishedcode/tasty-imitation-keyboard/commit/506d57bf0706d4ab8f164021a9ac1a6517f0c7eb

AaronFW commented 8 years ago

@polishedcode, do you know what is preventing your keyboard from having correct hight with iPad in Landscape? I am not sure whether or not is related, but the debugger also reports auto-layout constraint issues in CatboardBanner.Swift. (I need to do some more poking to identify the exact issues.)

simoncorstonoliver commented 8 years ago

sorry, I haven't done any debugging for iPad yet.

On Wed, Jul 20, 2016 at 9:53 AM, AaronFW notifications@github.com wrote:

@polishedcode https://github.com/polishedcode, do you know what is preventing your keyboard from having correct hight with iPad in Landscape? I am not sure whether or not is related, but the debugger also reports auto-layout constraint issues in CatboardBanner.Swift. (I need to do some more poking to identify the exact issues.)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/archagon/tasty-imitation-keyboard/issues/96#issuecomment-234010651, or mute the thread https://github.com/notifications/unsubscribe-auth/ALQ5GYa1VLQ7fcvbOxKWu9TlSYVc2Hevks5qXlKjgaJpZM4I0_Sc .

dawand commented 8 years ago

I also have issues with the iPad keyboard height. @polishedcode would it be possible to have a look at it please?

AaronFW commented 8 years ago

@dawand @polishedcode I've been a little slow to get to it, but I've gotten the iPad Landscape Keyboard Height to be acceptable now. (I have not tested it with iPad-Mini since there is no simulator.)

It might be somewhat 'hack' but I basically reused the code for the canonicalPortraitHeight and modified it for landscape and for iPad.

In keyboardViewController.swift, I updated the following function by adding the constant "let actualScreenHeight" and changing the "canonicalLandscapeHeight".

func heightForOrientation(orientation: UIInterfaceOrientation, withTopBanner: Bool) -> CGFloat {

        let actualScreenWidth = (UIScreen.mainScreen().nativeBounds.size.width /
            UIScreen.mainScreen().nativeScale)

        let actualScreenHeight = (UIScreen.mainScreen().nativeBounds.size.height / UIScreen.mainScreen().nativeScale)

        let canonicalPortraitHeight = CGFloat(orientation.isPortrait && actualScreenWidth >= 400 ? 226 : 216)

        let canonicalLandscapeHeight = CGFloat(orientation.isLandscape && actualScreenHeight >= 800 ? 330 : 162)

        let topBannerHeight = (withTopBanner && textDocumentProxy.keyboardType != UIKeyboardType.NumberPad && textDocumentProxy.keyboardType != UIKeyboardType.DecimalPad)
            ? metric("topBanner") : 0

        return CGFloat(orientation.isPortrait ? canonicalPortraitHeight + topBannerHeight : canonicalLandscapeHeight + topBannerHeight)

    }

There might be a better way to do it, or better numbers to use, but this seems to work making the keyboard the right size on iPads and iPhones.

simoncorstonoliver commented 8 years ago

Sounds good. It'll be a few days before I can review the fix.

On Monday, 8 August 2016, AaronFW notifications@github.com wrote:

@dawand https://github.com/dawand @polishedcode https://github.com/polishedcode I've been a little slow to get to it, but I've gotten the iPad Landscape Keyboard Height to be acceptable now. (I have not tested it with iPad-Mini since there is no simulator.)

It might be somewhat 'hack' but I basically reused the code for the canonicalPortraitHeight and modified it for landscape and for iPad.

In keyboardViewController.swift, I updated the following function by adding the constant "let actualScreenHeight" and changing the "canonicalLandscapeHeight".

func heightForOrientation(orientation: UIInterfaceOrientation, withTopBanner: Bool) -> CGFloat {

    let actualScreenWidth = (UIScreen.mainScreen().nativeBounds.size.width /
        UIScreen.mainScreen().nativeScale)

    let actualScreenHeight = (UIScreen.mainScreen().nativeBounds.size.height / UIScreen.mainScreen().nativeScale)

    let canonicalPortraitHeight = CGFloat(orientation.isPortrait && actualScreenWidth >= 400 ? 226 : 216)

    let canonicalLandscapeHeight = CGFloat(orientation.isLandscape && actualScreenHeight >= 800 ? 330 : 162)

    let topBannerHeight = (withTopBanner && textDocumentProxy.keyboardType != UIKeyboardType.NumberPad && textDocumentProxy.keyboardType != UIKeyboardType.DecimalPad)
        ? metric("topBanner") : 0

    return CGFloat(orientation.isPortrait ? canonicalPortraitHeight + topBannerHeight : canonicalLandscapeHeight + topBannerHeight)

}

There might be a better way to do it, or better numbers to use, but this seems to work making the keyboard the right size on iPads and iPhones.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/archagon/tasty-imitation-keyboard/issues/96#issuecomment-238088911, or mute the thread https://github.com/notifications/unsubscribe-auth/ALQ5Gd2UHHyIve_ZUv3rHnifz8rs99szks5qdfnfgaJpZM4I0_Sc .

simoncorstonoliver commented 8 years ago

Included dawand@'s fix.

On Sun, Aug 7, 2016 at 2:29 PM, Simon Corston-Oliver < simon@corston-oliver.com> wrote:

Sounds good. It'll be a few days before I can review the fix.

On Monday, 8 August 2016, AaronFW notifications@github.com wrote:

@dawand https://github.com/dawand @polishedcode https://github.com/polishedcode I've been a little slow to get to it, but I've gotten the iPad Landscape Keyboard Height to be acceptable now. (I have not tested it with iPad-Mini since there is no simulator.)

It might be somewhat 'hack' but I basically reused the code for the canonicalPortraitHeight and modified it for landscape and for iPad.

In keyboardViewController.swift, I updated the following function by adding the constant "let actualScreenHeight" and changing the "canonicalLandscapeHeight".

func heightForOrientation(orientation: UIInterfaceOrientation, withTopBanner: Bool) -> CGFloat {

    let actualScreenWidth = (UIScreen.mainScreen().nativeBounds.size.width /
        UIScreen.mainScreen().nativeScale)

    let actualScreenHeight = (UIScreen.mainScreen().nativeBounds.size.height / UIScreen.mainScreen().nativeScale)

    let canonicalPortraitHeight = CGFloat(orientation.isPortrait && actualScreenWidth >= 400 ? 226 : 216)

    let canonicalLandscapeHeight = CGFloat(orientation.isLandscape && actualScreenHeight >= 800 ? 330 : 162)

    let topBannerHeight = (withTopBanner && textDocumentProxy.keyboardType != UIKeyboardType.NumberPad && textDocumentProxy.keyboardType != UIKeyboardType.DecimalPad)
        ? metric("topBanner") : 0

    return CGFloat(orientation.isPortrait ? canonicalPortraitHeight + topBannerHeight : canonicalLandscapeHeight + topBannerHeight)

}

There might be a better way to do it, or better numbers to use, but this seems to work making the keyboard the right size on iPads and iPhones.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/archagon/tasty-imitation-keyboard/issues/96#issuecomment-238088911, or mute the thread https://github.com/notifications/unsubscribe-auth/ALQ5Gd2UHHyIve_ZUv3rHnifz8rs99szks5qdfnfgaJpZM4I0_Sc .

simoncorstonoliver commented 8 years ago

Correction, it was AaronFW@'s fix. Reading comprehension fail.