2014-09-22 86 views
1

错误是 - 无法找到支持类型4的键盘iPhone-Portrait-NumberPad ;使用3876877096_Portrait_iPhone-简单Pad_Default在iOS 7完成数字键盘键完全没问题,但在iOS 8没有。我没有改变任何东西,但只更新ios8

定义SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(V)([[[的UIDevice currentDevice] systemVersion]比较:V选项:NSNumericSearch]!= NSOrderedAscending)这种解决方案

- (void)keyboardWillShow:(NSNotification *)note 
{ 

    // NSLog(@"keyboardwillshow"); 
    doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    doneButton.frame = CGRectMake(0, 163, 106, 53); 
    doneButton.adjustsImageWhenHighlighted = NO; 

    [doneButton setTitle:@"Done" forState:UIControlStateNormal]; 
    [doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [doneButton addTarget:self action:@selector(dismissKeyboard1) forControlEvents:UIControlEventTouchUpInside]; 

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      // UIView *keyboardView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] firstObject]; 
      // [doneButton setFrame:CGRectMake(0, keyboardView.frame.size.height - 53, 106, 53)]; 
      // doneButton.frame = CGRectMake(0, ([UIScreen mainScreen].bounds.size.height-480)+163, 106, 53); 

      doneButton.frame = CGRectMake(0,163, 106, 53); 

      UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
      UIView* keyboard; 
      for(int i=0; i<[tempWindow.subviews count]; i++) { 
       keyboard = [tempWindow.subviews objectAtIndex:i]; 
       //     NSLog(@"%f",keyboard.frame.size.height); 
       // 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]; 
       } 
      } 




     // [keyboardView addSubview:doneButton]; 
      // [keyboardView bringSubviewToFront:doneButton]; 

      [UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02 
            delay:.0 
           options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue] 
          animations:^{ 
           self.view.frame = CGRectOffset(self.view.frame, 0, 0); 
          } completion:nil]; 
     }); 
    }else { 
     // locate keyboard view 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      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 
       if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES) 
        [keyboard addSubview:doneButton]; 
      } 
     }); 
    } 

} 
+0

去IGW?它不显示?它崩溃了吗?尽可能多地提供信息,不要过于宽泛或模糊 – 2014-09-22 08:34:15

回答

1

我遇到了麻烦,太,后来我发现这

how to get keyboard location in ios 8 & add DONE button on numberPad

你刚才添加addButtonToKeyboard方法,并调用它在textfieldEditingDidBegin代表,您在ADDB声明按钮uttonToKeyboard方法也是如此。

- (void)addButtonToKeyboard 
{ 
// create custom button 
self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
self.doneButton.frame = CGRectMake(0, 163+44, 106, 53); 
self.doneButton.adjustsImageWhenHighlighted = NO; 
[self.doneButton setTag:67123]; 
[self.doneButton setImage:[UIImage imageNamed:@"doneup1.png"] forState:UIControlStateNormal]; 
[self.doneButton setImage:[UIImage imageNamed:@"donedown1.png"] forState:UIControlStateHighlighted]; 

[self.doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside]; 

// locate keyboard view 
int windowCount = [[[UIApplication sharedApplication] windows] count]; 
if (windowCount < 2) { 
    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 found, add the button 

    if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES){ 
     UIButton* searchbtn = (UIButton*)[keyboard viewWithTag:67123]; 
     if (searchbtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard) 
      [keyboard addSubview:self.doneButton]; 

    }//This code will work on iOS 8.0 
    else 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){ 
       UIButton* donebtn = (UIButton*)[hostkeyboard viewWithTag:67123]; 
       if (donebtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard) 
        [hostkeyboard addSubview:self.doneButton]; 
      } 
     } 
    } 
else{} 
} 
} 

来隐藏它调用removeButtonFromKeyboard方法,并调用它在textfieldEditingDidEnd委托。

- (void)removeButtonFromKeyboard 
{ 
NSArray *arTemp = [[UIApplication sharedApplication] windows]; 
if ([arTemp count] <= 1) 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 found, add the button 
    if ([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
    { 
     for (id temp in keyboard.subviews) 
     { 
      if ([temp isKindOfClass:[UIButton class]]) 
      { 
       UIButton *btnDone = (UIButton*) temp; 
       [btnDone removeFromSuperview]; 
       break; 
      } 
     } 
    } 
    //This code will work on iOS 8.0 
    else 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) 
      { 
       for (id temp in hostkeyboard.subviews) 
       { 
        if ([temp isKindOfClass:[UIButton class]]) 
        { 
         UIButton *btnNext = (UIButton*) temp; 
         [btnNext removeFromSuperview]; 
         break; 
        } 
       } 
      } 
     } 
    } 
    else{} 
} 
} 

您仍然可以找到键盘iPhone-Portrait-NumberPad支持类型4的无法找到键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default错误,但您可以忽略它。

我推荐你试试这个,它的工作对我来说,所有的信用,你可以添加一个错误日志或什么是“不工作”的书面说明根据

+1

尽管此链接可能回答问题,但最好在此处包含答案的基本部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – Vaandu 2014-11-12 20:40:02

+0

它在编辑中已经修复 – Pugin 2014-11-12 20:53:27

相关问题