iOS 5中的UIKeyboardTypeNumberPad返回或完成按钮 [英] UIKeyboardTypeNumberPad return or done button in iOS 5

查看:219
本文介绍了iOS 5中的UIKeyboardTypeNumberPad返回或完成按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 3中,此解决方法涉及创建客户UIButton并将其作为子视图添加到Apple键盘。当iOS 4发布时,子视图被添加到更改的视图。所以要在iOS3& 4我有以下内容。

In iOS 3 this workaround involved creating a customer UIButton and adding this as a subview to the Apple keyboard. When iOS 4 was released the view that the subview was added to changed. So to get this working in iOS3 & 4 I had the following.

-(void) addDoneButtonToNumericKeyboard {
if(doneButtonIsAdded) {
    return;
}
if(doneButtonForNumericKeyboard == nil) {
    doneButtonForNumericKeyboard= [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    doneButtonForNumericKeyboard.frame = CGRectMake(0, 163, 106, 53);
    doneButtonForNumericKeyboard.adjustsImageWhenHighlighted = NO;
    if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) {
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
    } else {        
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    }
    [doneButtonForNumericKeyboard addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
}
// locate keyboard view
NSArray *winArray = [[UIApplication sharedApplication] windows];
if(winArray == nil || [winArray count] < 2) {
    NSLog(@"No winArray found!");
    return;
}
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
    keyboard = [tempWindow.subviews objectAtIndex:i];
    // keyboard view found; add the custom button to it
    NSLog(@"Keyboard description : %@", [keyboard description]);
    if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES || [[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
        NSLog(@"Attaching done button");
        [keyboard addSubview:doneButtonForNumericKeyboard];
        doneButtonIsAdded = YES;
    }
}
}

任何人有任何想法如何这适用于iOS 5吗?

Anyone have any ideas how to get this working for iOS 5?

上述两种方法都不适用于5.尝试添加似乎成功但未显示任何内容的子视图。该区域在屏幕上只是空白,并且不会响应触摸。

Neither of the methods above work for 5. There is an attempt to add the subview that seems to be successful but nothing is displayed. The area is just blank on screen and does not respond to a touch.

推荐答案

我也注意到这一点,唯一的解决方法是我到目前为止能够出现的是: keyboardWillShow: keyboardDidShow:。 will和did之间的区别显然是另一个讨论,但它似乎是根据我的需要修复它。

I noticed this as well and the only fix I was able to come up so far was to change it from: keyboardWillShow: to keyboardDidShow:. The difference between "will" and "did" is obviously another discussion but it seems that fixed it for my needs.

我希望这会有所帮助。

我发现的更多背景是 [[UIApplication sharedApplication] windows] 第一个对象似乎确实在那里但是第二个在索引1处,对象消失了。我想知道是什么造成的。

Some more background on what I found is that the [[UIApplication sharedApplication] windows] the first object does appear to be there but the second object, at index 1, is gone. I wonder what caused this.

谢谢。

这篇关于iOS 5中的UIKeyboardTypeNumberPad返回或完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆