Создание пользовательского UIKeyBoard для iPhone - PullRequest
0 голосов
/ 16 февраля 2010

Если у кого-нибудь есть приложение GymBuddy, то они поймут, о чем я говорю. Они, кажется, используют стандартную клавиатуру Number Pad, но добавили "." кнопка в левом нижнем углу, а также полоса сверху для переключения на буквенные символы. Кто-нибудь знает как это сделать? Сделать новый вид, например, клавиатуру, и потянуть ее вверх, чтобы кнопки соответствовали текстовому полю для ввода? Я не могу найти какую-либо информацию о настройке клавиатуры или создании собственной. Спасибо

Ответы [ 2 ]

5 голосов
/ 16 февраля 2010

Я сделал это. По сути, вы добавляете свою собственную кнопку в качестве подпредставления UIKeyboard следующим образом:

// This function is called each time the keyboard is going to be shown
- (void)keyboardWillShow:(NSNotification *)note {

// Just used to reference windows of our application while we iterate though them
UIWindow* tempWindow;

// 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];

    // Loop through all views in the current window
    for(int i = 0; i < [tempWindow.subviews count]; i++)
    {
        // Get a reference to the current view
        keyboard = [tempWindow.subviews objectAtIndex:i];

        // From all the apps i have made, they keyboard view description always starts with <UIKeyboard so I did the following
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
        {
            // Only add the Decimal Button if the Keyboard showing is a number pad. (Set Manually through a BOOL)
            if (numberPadShowing && [keyboard viewWithTag:123] == nil) {

                // Set the Button Type.
                dot = [UIButton buttonWithType:UIButtonTypeCustom];

                // Position the button - I found these numbers align fine (0, 0 = top left of keyboard)
                dot.frame = CGRectMake(0, 163, 106, 53);
                dot.tag = 123;

                // Add images to our button so that it looks just like a native UI Element.
                [dot setImage:[UIImage imageNamed:@"dotNormal.png"] forState:UIControlStateNormal];
                [dot setImage:[UIImage imageNamed:@"dotHighlighted.png"] forState:UIControlStateHighlighted];

                //Add the button to the keyboard
                [keyboard addSubview:dot];

                // When the decimal button is pressed, we send a message to ourself (the AppDelegate) which will then post a notification that will then append a decimal in the UITextField in the Appropriate View Controller.
                [dot addTarget:self action:@selector(sendDecimal:)  forControlEvents:UIControlEventTouchUpInside];

                return;
            }
            else if (numberPadShowing && [keyboard viewWithTag:123])
            {
                [keyboard bringSubviewToFront:dot];
            }
            else if (!numberPadShowing)
            {

                for (UIView *v in [keyboard subviews]){
                    if ([v tag]==123)
                        [v removeFromSuperview];
                }
            }
        }
    }
}
}

 - (void)sendDecimal:(id)sender {
// The decimal was pressed

}

Надеюсь, это понятно.

-Oscar

3 голосов
/ 28 апреля 2011

Проверьте это сообщение, это может быть ваш ответ:

UIKeyboardTypeNumberPad и отсутствующая клавиша «возврата»

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...