2015-04-10 19 views
5

Tôi đã thêm nút 'Đã hoàn tất' tùy chỉnh vào bàn phím số bằng cách sử dụng giải pháp được đăng trong các chủ đề khác, like this one. Đã xảy ra sự cố với bản cập nhật lên iOS 8.3, khi nút vẫn xuất hiện nhưng thông báo chạm không bao giờ tắt. Di chuyển nút từ chế độ xem bàn phím đến phần giám sát sẽ làm hỏng vị trí của nút nhưng chứng minh thông báo cho công việc kiểm soát.Nhận thông báo từ nút 'Hoàn tất' tùy chỉnh trên bàn phím số không hoạt động trong iOS 8.3

Nó hoạt động giống như nút tùy chỉnh nằm phía sau lớp trong suốt trên bàn phím và không thể chạm được.

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

Trả lời

4

Tôi đã gặp sự cố tương tự, tôi đã giải quyết vấn đề này bằng cách thêm nút trực tiếp trên UITextEffectsWindow. Ngoài ra tôi đã thay đổi khung nút.

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

giải pháp này có hoạt động cho mọi trường hợp không. tất cả iPhone và tất cả các phiên bản iOS? – hasan83

+1

chắc chắn, dự án của tôi hỗ trợ iOS 7+ –

0

objectAtIndex: 1 có thể không nhắm mục tiêu chỉ số cửa sổ mỗi lần. Vì vậy, mã nên kiểm tra bằng cách mô tả của nó cho dù cửa sổ là UITextEffectsWindow hay không như dưới đây.

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

} 
Các vấn đề liên quan