2014-09-25 13 views
5

Klavye konumunu bulmak için aşağıdaki kodu kullanıyorum & DONE düğmesine basın. Ancak, ios 8'de klavye konumu & alınamıyor DONE düğmesine basılmaz.ios 8'de klavye konumunu nasıl alabilirim ve numberPad üzerinde DONE düğmesine nasıl basın

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:@"<UIPeripheralHostView"] == YES) 
    { 
     [keyboard addSubview:doneButton]; 
    } 
} 

cevap

13

aşağıdaki kod Numberpad da iOS 8 üzerinde "TAMAM" butonuna gösteren içindir. Bu kodu XCode-5.1.1'de iOS 6/7/8 aygıtları ile çalıştırıyorum. Mükemmel çalışıyor.

Numara klavyesinde ekle düğmesi için bir kod verildiği zaman, bu bağlantıdan Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad cevabını alıyorum. AddButton

- (void)addButtonToKeyboard 
{ 
    if (!self.doneButton) 
    { 
     self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    } 
    self.doneButton.adjustsImageWhenHighlighted = NO; 
    [self.doneButton setTitle:@"DONE" forState:UIControlStateNormal]; 
    [self.doneButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]]; 
    [self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted]; 

    // locate keyboard view 
    if ([[[UIApplication sharedApplication] windows] 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) 
     { 
      BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); 
      self.doneButton.frame = CGRectMake(((isPortrait)?0:-1),((int) (keyboard.frame.size.height*3)/4) + ((isPortrait)?0:1),(int) keyboard.frame.size.width/3-1, (isPortrait)?60:40); 
      [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) 
       { 
        BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); 
        self.doneButton.frame = CGRectMake(((isPortrait) ? 0 : -1),((int) (hostkeyboard.frame.size.height*3)/4) + ((isPortrait) ? 0 : 1),(int) hostkeyboard.frame.size.width/3-1, (isPortrait) ? 60 : 40); 
        [hostkeyboard addSubview:self.doneButton]; 
       } 
      } 
     } 
     else{} 
    } 
} 

removeButtonFromKeyboard

- (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 *btnDone = (UIButton*) temp; 
          [btnDone removeFromSuperview]; 
          break; 
         } 
        } 
       } 
      } 
     } 
     else{} 
    } 
} 

@property (nonatomic, retain) UIButton *doneButton; 

bana herhangi bir sorun bildirin.

Güncelleme: iOS 7.1'de test etme, gerçek cihaz - klavye gösterisi animasyonu tamamlanmadıkça düğme eklenmez. Klavye tamamen görünür bir kez kod aşağıdaki düğmeye eklemek için bir gecikme ekler:

-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    [self performSelector:@selector(addButtonToKeyboard) withObject:nil afterDelay:0.75]; 

} 
+0

Benim için çalışır – poojathorat

+0

Gr8 işe yaradı, ama numpadden normal klavyeye metin alanını değiştirdiğimde, klavyenin önünde yapılmış düğme beliriyor ... ne yapmalıyım? – iAnurag

+0

"textFieldShouldEndEditing" temsilci yönteminde removeButtonFromKeyboard öğesini çağırmanız gerekir. Bu kadar. – alishaik786

0
  • Ben "Alex-taş" gibi yaptım ama özel düğmesini tıklayın olamaz.

  • Çözümümün:

// klavyeden

- (void)addDoneCustomReturnKeyButtonInKeyboard:(NSNotification *)notification 
{ 
NSArray *arr = [[[[UIApplication sharedApplication] windows] lastObject] subviews]; 
if (arr.count > 0) { 

    UIView *keyboardView = [arr objectAtIndex:0]; 
    float height; 
    if ([[keyboardView description] hasPrefix:@"<UIPeripheralHost"] == YES) { 
     height = (CGRectGetHeight(keyboardView.frame) - 
        CGRectGetHeight(self.navigationController.navigationBar.frame))/4; 

     [self.doneCustomReturnKeyButton setFrame:CGRectMake(0, keyboardView.frame.size.height - height, 
                  keyboardView.frame.size.width/3 - 2, height)]; 
     [keyboardView addSubview:self.doneCustomReturnKeyButton]; 
    } 
    //This code will work on iOS 8.0 
    else if([[keyboardView description] hasPrefix:@"<UIInputSetContainerView"] == YES) 
    { 
     for(int i = 0 ; i < [keyboardView.subviews count] ; i++) 
     { 
      UIView* hostkeyboard = [keyboardView.subviews objectAtIndex:i]; 
      if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) 
      { 
       UIButton* donebtn = (UIButton*)[hostkeyboard viewWithTag:67123]; 
       if (donebtn == nil) 
       { 
        height = (CGRectGetHeight(hostkeyboard.frame) - 
           CGRectGetHeight(self.navigationController.navigationBar.frame))/4; 

        [self.doneCustomReturnKeyButton setFrame:CGRectMake(0, keyboardView.frame.size.height - height, 
                     keyboardView.frame.size.width/3 - 2, height)]; 

        [keyboardView addSubview:self.doneCustomReturnKeyButton]; 
       } 
      } 
     } 
    } 
} 
else { 
    self.doneCustomReturnKeyButton.hidden = YES; 
} 

}

içine ekleyip düğmesi oluşturmak için DoneCustomReturnKeyButton oluşturun.

- (void)createDoneCustomReturnKeyButton 
{ 
    self.doneCustomReturnKeyButton = [UIButton buttonWithType:UIButtonTypeSystem]; 
    [self.doneCustomReturnKeyButton setTitle:NSLocalizedString(@"NEXT", nil) forState:UIControlStateNormal]; 
    [self.doneCustomReturnKeyButton.titleLabel setFont:[UIFont systemFontOfSize:20]]; 
    self.doneCustomReturnKeyButton.adjustsImageWhenHighlighted = NO; 
    self.doneCustomReturnKeyButton.backgroundColor = [UIColor lightGrayColor]; 
    [self.doneCustomReturnKeyButton setTintColor:[UIColor whiteColor]]; 
    [self.doneCustomReturnKeyButton addTarget:self 
             action:@selector(doneCustomReturnKeyButtonAction:) 
          forControlEvents:UIControlEventTouchUpInside]; 
} 
0

Tamam burada hem iOS 9'da benim uygulamasında gösterilmesi için düğmeye ve iş 'done' koyulmak için basit bir düzeltme var, iOS 8 ve benzer hata var aşağıda. Bir uygulamanın çalıştırılmasından ve uygulamanın 'Görünüm Hiyerarşisi'nden (ör. Uygulamacihaz cihazında çalışırken ve Görünümlerinizin Storyboard'da incelenmesinden' Görünüm Hiyerarşisi 'simgesine tıklanarak) görülebilmesi, klavyenin iOS 8’deki farklı pencerelerde iOS 8’e ve aşağıdaki sürümlere kıyasla sunulacak ve bunların muhasebeleştirilmesi gerekiyor. addButtonToKeyboard

- (id)addButtonToKeyboard 
{ 
if (!doneButton) 
{ 
    // create custom button 
    UIButton * doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    doneButton.frame = CGRectMake(-2, 163, 106, 53); 
    doneButton.adjustsImageWhenHighlighted = NO; 
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal]; 
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted]; 
    [doneButton addTarget:self action:@selector(saveNewLead:) forControlEvents:UIControlEventTouchUpInside]; 
} 

NSArray *windows = [[UIApplication sharedApplication] windows]; 
//Check to see if running below iOS 9,then return the second window which bears the keyboard 
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) { 
return windows[windows.count - 2]; 
} 
else { 
UIWindow* keyboardWithDoneButtonWindow = [ windows lastObject]; 
return keyboardWithDoneButtonWindow; 
    } 
} 

Ve bu klavyeden yapabildin removeKeyboardButton İstersen nasıl.Eğer UITextfieldsDelegeates yöntemlerle Eğer

- (void)removeKeyboardButton { 

id windowTemp = [self addButtonToKeyboard]; 

if (windowTemp) { 

    for (UIView *doneButton in [windowTemp subviews]) { 
     if ([doneButton isKindOfClass:[UIButton class]]) { 
      [doneButton setHidden:TRUE]; 
     } 
    } 
    } 
} 

, sadece textFieldDidBeginEditing temsilci yönteminde addButtonToKeyboard yöntemini çağırabilirsiniz ve bu yapmalı. Şimdi, NumberPad ve Varsayılan klavye arasında ileri geri geçiş yaparsanız, herhangi bir aksaklığı önlemek için "textFieldShouldEndEditing" delegesi yönteminde removeKeyboardButton numaralı çağrıyı çağırmanız önerilir.

İlgili konular