lnafziger / Numberpad

iOS Custom Numberpad
MIT License
79 stars 28 forks source link

Landscape and portrait keyboard height #3

Closed Stan92 closed 11 years ago

Stan92 commented 11 years ago

Hello, Is it possible do manage the orientation event? I mean, in portrait mode have a height of 264px and in landscape 352px. I don't know where to control the size as well as to have the current orientation before the keyboard appears. I tried to add the shouldAutorotateToInterfaceOrientation within the LNNumberpad.m but it is never invoked.. Any help? Thanks

lnafziger commented 11 years ago

You would have to do this in the view controller that is displaying the keyboard by subscribing to the keyboard events so that you know when the keyboard is shown in order to adjust its size.

You would subscribe to the keyboard notification like this:

// In viewDidLoad
// register for keyboard notifications - Be sure to unregister in viewDidUnload
[[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(keyboardDidShow)
                                         name:UIKeyboardDidShowNotification
                                       object:nil];

And then you implement your own custom keyboardDidShow method:

- (void)keyboardDidShow {
    // Find the keyboard view - Copied from http://iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-to-custimize-a-keyboard.html
    // Note that I have not tested this, so please let me know how it works!
    UIWindow* tempWindow;
    UIView *tempKeyboard;

    //Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
    //UIKeyboard is a subclass of UIView anyways
    UIView* keyboard;

    //Check each window in our application
    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
        //Get a reference of the current window
        tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];

        //Get a reference of the current view 
        for(int i = 0; i < [tempWindow.subviews count]; i++)
        {
            tempKeyboard = [tempWindow.subviews objectAtIndex:i];
            if([tempKeyboard isKindOfClass:[LNNumberpad class]] == YES)
            {
                //If we get to this point, then our UIView \"keyboard\" is referencing our keyboard.
                keyboard = tempKeyboard;
                break;
            }
        }
    }

    if (keyboard)
    {
        // Customize the size of the keyboard view.
    }
}