IOS 8 custom keyboard looks pretty slow

I am trying to create a custom keyboard using Swift for iOS 8, and I created each button programmatically. When switching to the user’s keyboard from the built-in keyboard for the first time, this is rather slow, since it took about 2 seconds. I'm not quite sure if I am doing this correctly. Below is my code and I am just showing 2 buttons, but there is a lot more:

class KeyboardViewController: UIInputViewController { @IBOutlet var nextKeyboardButton: UIButton! @IBOutlet var qButton: UIButton! var buttonFontSize:CGFloat = 22.0 var gapBtwButton:CGFloat = +7.0 // a lot more button below override func updateViewConstraints() { super.updateViewConstraints() // Add custom view sizing constraints here } override func viewDidLoad() { super.viewDidLoad() setupEnKeyboard() } func setupEnKeyboard(){ println("setupEnKeyboard") addEnKeyboardButtons() } func addEnKeyboardButtons() { addQButton() addNextKeyboardButton() // a lot more button to be added } func setupButton(label: String, functionName: Selector, imageOnButton: String) -> UIButton { // initialize the button let keyButton:UIButton = UIButton.buttonWithType(.System) as UIButton var testVar: String? = imageOnButton if imageOnButton.isEmpty { keyButton.setTitle(label, forState: .Normal) } else { let image = UIImage(named: imageOnButton) as UIImage keyButton.setImage(image, forState: .Normal) } keyButton.sizeToFit() keyButton.setTranslatesAutoresizingMaskIntoConstraints(false) // adding a callback keyButton.addTarget(self, action: functionName, forControlEvents: .TouchUpInside) // make the font bigger keyButton.titleLabel?.font = UIFont.systemFontOfSize(self.buttonFontSize) // add rounded corners keyButton.backgroundColor = UIColor(white: 0.9, alpha: 1) keyButton.setTitleColor(UIColor.blackColor(), forState: .Normal) keyButton.layer.cornerRadius = 5 return keyButton } func addQButton() { qButton = setupButton("Q", functionName:"didTapQButton", imageOnButton:"") view.addSubview(qButton) var leftSideConstraint = NSLayoutConstraint(item: qButton, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: +6.0) var topConstraint = NSLayoutConstraint(item: qButton, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: +10.0) view.addConstraints([leftSideConstraint, topConstraint]) } func didTapQButton(){ var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("q") } func addNextKeyboardButton() { nextKeyboardButton = setupButton("N", functionName:"advanceToNextInputMode", imageOnButton:"globe") view.addSubview(nextKeyboardButton) var leftSideConstraint = NSLayoutConstraint(item: nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: showNumbersButton, attribute: .Right, multiplier: 1.0, constant: self.gapBtwButton) var bottomConstraint = NSLayoutConstraint(item: nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: -3.0) view.addConstraints([leftSideConstraint, bottomConstraint]) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated } override func textWillChange(textInput: UITextInput) { // The app is about to change the document contents. Perform any preparation here. } override func textDidChange(textInput: UITextInput) { // The app has just changed the document contents, the document context has been updated. var textColor: UIColor var proxy = self.textDocumentProxy as UITextDocumentProxy if proxy.keyboardAppearance == UIKeyboardAppearance.Dark { textColor = UIColor.whiteColor() } else { textColor = UIColor.blackColor() } //self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal) } } 

Please rate any comments, please :)

Thanks Mark Thien

+7
ios8
source share

No one has answered this question yet.

See related questions:

51
Today, the iPad’s extension height is much higher than indicated
40
nil in iOS8 delegate methods - custom keyboards
21
What is the speed of keyboard animation appearing in iOS8?
3
TextField Keyboard Not Displaying
3
Custom keyboard on iOS 8 ruined emerging animation
one
iOS8: When the keyboard appears and press the back button, while the next view looks very slow
one
Is the custom keyboard look always dark?
0
Add audio file to iOS custom keyboard
0
Ios 8 user keyboard Appears with a delay
0
IOS Custom Keyboard - Saving State between Appearances

All Articles