2015-04-10 18 views
5

में काम नहीं कर रहे संख्यात्मक कीबोर्ड पर कस्टम 'संपन्न' बटन से अधिसूचनाएं प्राप्त करना मैंने अन्य धागे, like this one में पोस्ट किए गए समाधान का उपयोग करके संख्यात्मक कीपैड में एक कस्टम 'संपन्न' बटन जोड़ा है। आईओएस 8.3 में अपडेट के साथ कुछ बदल गया है, क्योंकि बटन अभी भी दिखाई देता है लेकिन स्पर्श अधिसूचनाएं कभी भी बंद नहीं होतीं। कीबोर्ड दृश्य से बटन को पर्यवेक्षण में बटन को स्थानांतरित करना बटन के स्थान को खंडित करता है, लेकिन नियंत्रण कार्य के लिए अधिसूचनाएं साबित करता है।आईओएस 8.3

ऐसा लगता है कि कस्टम बटन कीबोर्ड पर एक पारदर्शी परत के पीछे है और कोई स्पर्श नहीं हो पाता है।

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

उत्तर

4

मुझे एक ही समस्या थी, मैंने सीधे UITextEffectsWindow पर बटन जोड़कर इस समस्या को हल किया। इसके अलावा मैंने बटन फ्रेम बदल दिया है।

- (void)addButtonToKeyboar { 
// create custom button 
self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
self.doneButton.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 53, [[UIScreen mainScreen] bounds].size.width/3, 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]; 
UIButton* donebtn = (UIButton*)[tempWindow viewWithTag:67123]; 
if (donebtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard) 
    [tempWindow addSubview:self.doneButton]; } 
+0

यह समाधान सभी मामलों के लिए काम करता है। सभी आईफोन और सभी आईओएस संस्करण? – hasan83

+1

यकीन है, मेरी परियोजना आईओएस 7+ का समर्थन करता है –

0

objectAtIndex: 1 खिड़की सूचकांक हर बार लक्ष्य नहीं बनाते। तो कोड को इसके विवरण से जांच करनी चाहिए कि क्या विंडो UITextEffectsWindow है या नीचे नहीं है।

if (windowCount < 2) { 
    return; 

} else { 
    periodButton.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 53, 106, 53); 
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) { 
     if ([[window description] hasPrefix:@"<UITextEffectsWindow"]) { 
      [window addSubview:periodButton]; 
     } 
    } 

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