Make custom keyboard non-movable

540 views Asked by At

We created a custom numeric keypad for iPad. On our testers iPad this keyboard was suddenly moved out of place and it took us quite a while to figure out that it is possible to move that custom keyboard by start dragging at the location where the "Keyboard Button" would normally be located.

The customers will have very hard times to move it back in case they accidentally moved it. As it makes no sense to move the keyboard on that specific input screen I would rather prefer to prevent the keyboard from moving instead of painting some kind of handle that makes visible to the users that the keyboard can be moved. (This is a special input screen for just editing one single numeric value. The keyboard is like part of the layout and is always visible on this screen.)

I tried hard but could not find a way to prevent the keyboard from moving when dragged on this specific place. Even all my dirty ideas like removing possibly preexisting GestureRecognizers (there were none) or placing my own button in front did not help.

Edit: The keyboard is even movable in the simplest possible custom keyboard app written in Monotouch I can think of. Did I missed something?

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace KeyboardTest
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        private UIWindow window;
        private UIViewController viewController;
        private UIViewController keyboardViewController;

        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);

            // Create a red dummy keyboard
            keyboardViewController = new UIViewController();
            keyboardViewController.View.BackgroundColor = UIColor.Red;

            // Create a textfield and assign our beautiful red keyboard as its InputView
            UITextField textField = new UITextField();
            textField.BorderStyle = UITextBorderStyle.RoundedRect;
            textField.Frame = new System.Drawing.RectangleF(44, 44, 200, 44);
            textField.InputView = keyboardViewController.View;

            // create a rootview controller and add our textfield
            viewController = new UIViewController();
            viewController.View.AddSubview(textField);

            window.RootViewController = viewController;
            window.MakeKeyAndVisible ();

            return true;
        }
    }
}
1

There are 1 answers

3
Marcal On

For what you explain, I´m guessing that you have your keyboard as a subview of your main view. Instead, I would set it as a inputView of the UItextFields and then make the first of your textFields be the firs responder on viewDidLoad. Something like:

-(void)viewDidLoad{

[super viewDidLoad];

CustomkeyPad *keypad=[[CustomKeyPad alloc]init];  // initWithFrame would probably be better

self.textField.delegate=self;
self.textField.inputView=keypad;
[self.textField becomeFirstResponder];

}

I´m not in my Mac so I made probably some mistake here, but that´s the idea and That´s how I did it when I did my custom keypad as well and it´s universal (iPad and iPhone) for both landscape and portrait modes and so far it has given me no problems.