键盘上的自定义按钮并不总是显示出来

时间:2012-03-15 16:29:08

标签: objective-c ios cocoa-touch uitextfield

我在编辑UITextField时向手机键盘添加了一个自定义按钮。该按钮应该隐藏键盘,但是,如果我在启动我的应用程序之前,使用了表情符号符号键盘,在另一个应用程序中,键盘保持在该布局中。当我进入应用程序时,如何让它自动更改为手机板布局?

我尝试使用calculatingField.keyboardType = UIKeyboardTypePhonePad;,但只有在我没有使用表情符号键盘的情况下才有效。

以下两个屏幕截图可以更好地解释它:

如果我在发布之前没有使用表情符号键盘,那么它应该是什么样子,看起来如何: img one

如果我在启动我之前在另一个应用程序中使用表情符号键盘,这就是它的样子: img two

- (void)addButtonToKeyboard {    
UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeCustom];  
yourButton.frame = CGRectMake(0, 163, 105, 53);  
yourButton.adjustsImageWhenHighlighted = NO;  
yourButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];  

[yourButton setTitle:@"FÆRDIG" forState:UIControlStateNormal];  
[yourButton setTitleColor:[UIColor colorWithRed:0.302f green:0.33f blue:0.384f alpha:1.0f] forState:UIControlStateNormal];  
[yourButton setBackgroundImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];  

[yourButton setTitle:@"FÆRDIG" forState:UIControlStateHighlighted];  
[yourButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];  
[yourButton setBackgroundImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];  

[yourButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];  

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];  
UIView* keyboard;  
for(int i=0; i<[tempWindow.subviews count]; i++) {  
    keyboard = [tempWindow.subviews objectAtIndex:i];  

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {  
        if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)  
            [keyboard addSubview:yourButton];  
    } else {  
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)  
            [keyboard insertSubview:yourButton atIndex:100];  
    }  
}  
}

0 个答案:

没有答案
相关问题