keyboard - 从数字键盘上的自定义 'Done' 按钮接收通知在 iOS 8.3 中不起作用

标签 keyboard ios8.3

我使用其他线程中发布的解决方案 like this one 在数字键盘上添加了一个自定义“完成”按钮。 。 iOS 8.3 更新后,情况发生了变化,按钮仍然出现,但触摸通知永远不会触发。将按钮从键盘 View 移动到 super View 会破坏按钮的位置,但证明了控制工作的通知。

它的行为就像自定义按钮位于键盘上的透明层后面,并且无法进行触摸。

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

最佳答案

我遇到了同样的问题,我通过直接在 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]; }

关于keyboard - 从数字键盘上的自定义 'Done' 按钮接收通知在 iOS 8.3 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572215/

相关文章:

iOS 8.3 : UIActivityViewController shows extraneous row

ios - 在 iPad 的 iOS 8.3 上关闭 UIAlertView 后键盘弹出

css - 在网络应用中隐藏iOS键盘选项卡栏

java - 有没有办法在没有 JFrame 的情况下获取键盘事件?

android - Android 应用程序如何加载键盘?

terminal - VS Code 终端不会将选项键映射到元

cocoa - UIImageView 不会随图像调整大小

wpf - 响应WPF中的 "Back"和 "Forward"按钮

ios - 指向同一地址的两个对象不起作用。例如新数组 = 旧数组