在iOS 3中,此解决方法涉及创建客户UIButton并将其作为子视图添加到Apple键盘。当iOS 4发布时,子视图被添加到更改的视图。所以要在iOS3& 4我有以下内容。
-(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?
上述两种方法都不适用于5.尝试添加似乎成功但未显示任何内容的子视图。该区域在屏幕上只是空白,并且不会响应。
答案 0 :(得分:9)
我也注意到了这一点,到目前为止我唯一能够解决的问题是将其从keyboardWillShow:
更改为keyboardDidShow:
。 “遗嘱”和“遗嘱”之间的区别显然是另一种讨论,但似乎根据我的需要修复了它。
我希望这会有所帮助。
我发现的更多背景是[[UIApplication sharedApplication] windows]
第一个对象确实存在,但第二个对象(索引1)消失了。我想知道是什么造成的。
感谢。
答案 1 :(得分:0)
我很幸运能找到这个:
替换: if([[keyboard description] hasPrefix:@“
使用: if([[[[UIDevice currentDevice] systemVersion] floatValue]&gt; = 3.2){ if([[keyboard description] hasPrefix:@“