2015-04-10 10 views
5

Dodałem niestandardowy przycisk "Gotowe" do klawiatury numerycznej za pomocą rozwiązania zamieszczonego w innych wątkach, like this one. Coś się zmieniło wraz z aktualizacją do iOS 8.3, ponieważ przycisk nadal się wyświetla, ale powiadomienia dotykowe nigdy się nie wyłączają. Przesunięcie przycisku z widoku klawiatury do podglądu powoduje zniszczenie lokalizacji przycisku, ale potwierdza powiadomienia o pracy kontrolnej.Otrzymywanie powiadomień z niestandardowego przycisku "Gotowe" na klawiaturze numerycznej nie działa w systemie iOS 8.3

Zachowuje się tak, jak przycisk niestandardowy znajduje się za przezroczystą warstwą na klawiaturze i nie można ich dotknąć.

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

Odpowiedz

4

Miałem ten sam problem, rozwiązałem ten problem, dodając przycisk bezpośrednio na UITextEffectsWindow. Zmieniłem także ramkę przycisku.

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

czy to rozwiązanie działa we wszystkich przypadkach. wszystkie iPhony i wszystkie wersje iOS? – hasan83

+1

z pewnością mój projekt obsługuje iOS 7+ –

0

objectAtIndex: 1 nie może kierować indeks okno za każdym razem. Kod powinien więc sprawdzić po jego opisie, czy okno to UITextEffectsWindow, czy nie, jak poniżej.

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

} 
Powiązane problemy