在我们公司的iPhone应用程序中,我们使用数字键盘键盘和自定义按钮连字符“ - ”。在整个iOS版本中,我们必须修改如下代码。 直到iOS 10,下面的代码工作正常,但我们在iOS11中遇到了问题。当我点击屏幕#1上的文本框时,键盘和“ - ”按预期显示。当我点击同一屏幕#1上的输入按钮时,应用程序将我带到屏幕#2,但当我点击屏幕#2上的后退按钮,并点击屏幕#1中的同一文本框时,键盘会再次显示但连字符键没有。 希望你能帮忙。谢谢。 我们也在寻找一个永久的解决方案,以便我们不必在iOS12等中重新审视相同的问题。
- (void)addButtonToKeyboard
{
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
float iOSF=[iOSVersion floatValue];
if(iOSF <= 7.2)
{
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
} else {
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
else if (iOSF >=8.0 && iOSF <8.3 )
{
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0)
{
[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
else
{
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
}
else
{
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)
{
for(int i = 0 ; i < [keyboard.subviews count] ; i++)
{
UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES)
{
BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
doneButton.frame = CGRectMake(((isPortrait) ? 0 : -1),((int) (hostkeyboard.frame.size.height*3)/4) + ((isPortrait) ? 0 : 1),(int) hostkeyboard.frame.size.width/3-1, (isPortrait) ? 54 : 38);
[hostkeyboard addSubview:doneButton];
}
}
}
else{}
}
}
else if (iOSF >= 8.3 && iOSF <=8.5)
{
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
// create custom button
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 53, [[UIScreen mainScreen] bounds].size.width / 3, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTag:67123];
[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
//doneButton1.hidden=false;
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillChangeFrameNotification object:nil];
// locate keyboard view
int windowCount = [[[UIApplication sharedApplication] windows] count];
if (windowCount < 2) {
return;
}
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
// doneButton = (UIButton*)[tempWindow viewWithTag:67123];
// if (doneButton == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
[tempWindow addSubview:doneButton];
}
else{
UIButton *doneButton1 ;
UIWindow* tempWindow1;
doneButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
// create custom button
doneButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton1.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 53, [[UIScreen mainScreen] bounds].size.width / 3, 53);
doneButton1.adjustsImageWhenHighlighted = NO;
[doneButton1 setTag:67123];
[doneButton1 setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton1 setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
//doneButton1.hidden=false;
[doneButton1 addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillChangeFrameNotification object:nil];
// locate keyboard view
int windowCount = [[[UIApplication sharedApplication] windows] count];
if (windowCount < 2) {
return;
}
tempWindow1 = [[[UIApplication sharedApplication] windows] objectAtIndex:2];
// doneButton = (UIButton*)[tempWindow viewWithTag:67123];
// if (doneButton == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
[tempWindow1 addSubview:doneButton1];}
}
//Addind button to keypad "-"
- (void)keyboardWillShow:(NSNotification *)note
{
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2)
{
[self addButtonToKeyboard];
}
}
//Addind button to keypad "-"
- (void)keyboardDidShow:(NSNotification *)note
{
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
[self addButtonToKeyboard];
}
}
//Adds dash button to keyboard
- (void)doneButton:(id)sender
{
@try {
enterTxtBox.text = [enterTxtBox.text stringByAppendingString:@"-"];
}
@catch (NSException *exception) {
}
@finally {
}
}
-(void)onKeyboardHide:(NSNotification *)notification
{
//- key on keyboard will hide
doneButton.hidden=true;
}