tasty-imitation-keyboard
tasty-imitation-keyboard copied to clipboard
Reload the keyboard using the in-keyboard settings
Hi, I put an option in the settings to change the keyboard characters to switch from qwerty to azerty I made a
func myKeyboard() -> Keyboard {
let myKeyboard = Keyboard()
if preference.isQwerty {
build qwerty
}else{
build azerty
}
return my keyboard
}
and a
class MyKB: KeyboardViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.keyboard = myKeyboard() //seems to be set only here
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
...
I overriden createSettings and @IBAction override func toggleSettings()
the value of preference.isQwerty is set correctly but I do not know what command to use to change the characters at the close of the settings and where call it
I tried to write self.keyboard = myKeyboard() after changing the setting but does not works
*If I hit the globe button and change the keyboard when appears again is set and works correctly
do you have any advice?
thanks
Have you figured this out?
You need to modify the actual views of the keys. The Keyboard class only points to the Keys. Changing the Keyboard will not change the views.
I have also overriden toggleSettings()
. In my case, I added an extra instance variable to the key class called letter
. From there, I ran the following code in my toggleSettings()
function:
let pages : [Page] = self.keyboard.pages
for page in pages {
let rows : [[Key]] = page.rows
for row in rows {
for key in row {
if key.letter != nil {
key.setLetter(key.letter!)
}
}
}
}
I checked a lot of forks and made a func and use a bool to track the changes in settings
class KeyboardViewController: UIInputViewController {
func rebootKeyboard() {
//if #NSUserDefaults group#.boolForKey("rebootKeyboard") {
// call to function to set new letters arrays
self.keyboard = mKeyboard() // mKeyboard() -> Keyboard (create all the keys and pages with updated values)
self.forwardingView.resetTrackedViews()
self.shiftStartingState = nil
self.shiftWasMultitapped = false
self.layout?.rasterizeKeys(true)
self.forwardingView.removeSubviews()
self.keyboardHeight = self.heightForOrientation(self.currentInterfaceOrientation, withTopBanner: false)
self.constraintsAdded = false
self.setupLayout()
#NSUserDefaults group#.setBool(false, forKey: "rebootKeyboard") //reset the bool
#NSUserDefaults group#.synchronize()
//}
}
}
I call it this way
class TheKeybo: KeyboardViewController {
@IBAction override func toggleSettings() { //
[...]
if #NSUserDefaults group#.boolForKey("rebootKeyboard") {
rebootKeyboard() //called only if settings changed
}
[...]
}
}
I use it in a published app but i get some crashes on the extension but only 1 crash each
PlugInKit: -[PKService run]
CoreText: bool TAATMorphSubtableMorx::FetchInitialClass
and others - i do not use full access