2014-09-25 7 views
5

मैं कीबोर्ड कोड को & से देखने के लिए नीचे दिए गए कोड का उपयोग कर रहा हूं। इसमें आईओएस 8 में यह कीबोर्ड स्थान & प्राप्त करने में सक्षम नहीं है बटन नहीं जोड़ा गया।आईओएस 8 में कीबोर्ड स्थान कैसे प्राप्त करें और नंबर पर डोन बटन जोड़ें

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]; 
    } 
} 

उत्तर

13

नीचे कोड numberpad iOS 8 भी पर "पूर्ण" बटन दिखाने के लिए है। मैं इस कोड को XCode-5.1.1 में आईओएस 6/7/8 डिवाइस के साथ चलाता हूं। यह पूरी तरह से काम कर रहा है।

मैं इस लिंक से प्रतिबिंब लेता हूं Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad संख्या कीबोर्ड पर जोड़ने के लिए कुछ कोड दिया गया।

@property (nonatomic, retain) UIButton *doneButton; 

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{} 
    } 
} 

मुझे किसी भी मुद्दे जानते हैं।

अद्यतन: आईओएस 7.1, वास्तविक डिवाइस पर परीक्षण - बटन तब तक नहीं जोड़ा जा रहा है जब तक कीबोर्ड शो एनीमेशन समाप्त नहीं हो जाता है। कोड नीचे दिए गए बटन को जोड़ने के लिए एक देरी कहते हैं एक बार कुंजीपटल पूरी तरह से दिखाई दे रहा है:

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

} 
+0

धन्यवाद यह मेरे लिए काम करता है – poojathorat

+0

Gr8 यह काम करता है, लेकिन जब मैं टेक्स्टफील्ड को नमपैड से सामान्य कीबोर्ड में बदलता हूं तो किया गया बटन कुंजीपटल के सामने दिखाई देता है .. मुझे क्या करना चाहिए? – iAnurag

+0

आपको "textFieldShouldEndEditing" प्रतिनिधि विधि में removeButtonFromKeyboard को कॉल करना होगा। बस। – alishaik786

0
  • मैं की तरह "एलेक्स-पत्थर" किया था, लेकिन मैं कस्टम बटन क्लिक करने के लिए नहीं कर सकते।

  • मेरे समाधान:

// कुंजीपटल

- (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; 
} 

}

में जोड़ सकते हैं और बटन बनाने के लिए DoneCustomReturnKeyButton पैदा करते हैं।

- (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

ठीक है यहाँ हो रही दोनों आईओएस 9 में मेरे एप्लिकेशन में बटन को दिखाने के लिए और काम 'पूर्ण' के लिए उन्हें आसानी से ठीक है, iOS 8 और नीचे जब मैं इसी तरह की त्रुटि मिली। इसे ऐप चलाने और इसे 'व्यू पदानुक्रम' के माध्यम से देखने के बाद देखा जा सकता है (यानी डीबग एरिया बार से 'व्यू पदानुक्रम' आइकन पर क्लिक करते हुए ऐप डिवाइस पर चल रहा है और स्टोरीबोर्ड में आपके विचारों का निरीक्षण कर रहा है), कि कीबोर्ड है आईओएस 8 और आईओएस संस्करणों की तुलना में आईओएस 9 में विभिन्न विंडोज़ पर प्रस्तुत किया गया है और इसके लिए जिम्मेदार होना चाहिए। 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; 
    } 
} 

और यह कैसे कीबोर्ड से आप कर सकते थे removeKeyboardButton आप चाहते हैं।

- (void)removeKeyboardButton { 

id windowTemp = [self addButtonToKeyboard]; 

if (windowTemp) { 

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

आप UITextfieldsDelegeates तरीकों का उपयोग कर, तो आप बस textFieldDidBeginEditing प्रतिनिधि विधि में addButtonToKeyboard विधि कॉल कर सकते हैं और है कि यह करना चाहिए। अब यदि आप नंबरपैड और डिफॉल्ट कीबोर्ड के बीच आगे और पीछे टॉगल करते हैं, तो यह अनुशंसा की जाती है कि आप किसी भी दुर्घटना को रोकने के लिए "textFieldShouldEndEditing" प्रतिनिधि विधि में हटाएं KeyboardButton पर कॉल करें।

संबंधित मुद्दे