Keyboard 从custom'接收通知;完成';数字键盘上的按钮在iOS 8.3中不起作用

Keyboard 从custom'接收通知;完成';数字键盘上的按钮在iOS 8.3中不起作用,keyboard,ios8.3,Keyboard,Ios8.3,我使用其他线程中发布的解决方案,在数字键盘上添加了一个自定义的“完成”按钮。随着iOS 8.3的更新,有些东西发生了变化,按钮仍然出现,但触摸通知从未熄灭。将按钮从键盘视图移动到superview会破坏按钮的位置,但会证明控件工作的通知 它的行为就像自定义按钮位于键盘上的透明层后面,无法进行任何触摸 - (void)addButtonToKeyboard { // create custom button self.doneButton = [UIButton buttonWithType:UI

我使用其他线程中发布的解决方案,在数字键盘上添加了一个自定义的“完成”按钮。随着iOS 8.3的更新,有些东西发生了变化,按钮仍然出现,但触摸通知从未熄灭。将按钮从键盘视图移动到superview会破坏按钮的位置,但会证明控件工作的通知

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

- (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];
            }
        }
    }
}
}
-(无效)添加按钮键盘
{
//创建自定义按钮
self.doneButton=[UIButton-buttonwhithtype:UIButtonTypeCustom];
self.doneButton.frame=CGRectMake(0,163+44,106,53);
self.doneButton.adjustsImageWhenHighlighted=否;
[self.doneButton setTag:67123];
[self.doneButton setImage:[UIImage ImageName:@“doneup1.png”]用于状态:UIControlStateNormal];
[self.doneButton setImage:[UIImage ImageName:@“donedown 1.png”]用于状态:UIControlStateHighlighted];
[self.doneButton addTarget:self action:@selector(doneButton:)for controlEvents:UIControlEventTouchUpInside];
//定位键盘视图
int windowCount=[[UIApplication sharedApplication]windows]计数];
如果(windowCount<2){
返回;
}
UIWindow*tempWindow=[[UIApplication sharedApplication]windows]对象索引:1];
UIView*键盘;
对于(int i=0;i<[tempWindow.subviews计数];i++)
{
键盘=[tempWindow.subviews objectAtIndex:i];
//找到键盘后,添加按钮

如果([[keyboard description]hasPrefix:@“我也遇到了同样的问题,我通过直接在UITextEffectsSwindow上添加按钮解决了这个问题。我还更改了按钮框架

- (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]; }
-(void)addButtonToKeyboar{
//创建自定义按钮
self.doneButton=[UIButton-buttonwhithtype:UIButtonTypeCustom];
self.doneButton.frame=CGRectMake(0,[[UIScreen mainScreen]边界].size.height-53,[[UIScreen mainScreen]边界].size.width/3,53);
self.doneButton.adjustsImageWhenHighlighted=否;
[self.doneButton setTag:67123];
[self.doneButton setImage:[UIImage ImageName:@“doneup1.png”]用于状态:UIControlStateNormal];
[self.doneButton setImage:[UIImage ImageName:@“donedown 1.png”]用于状态:UIControlStateHighlighted];
[self.doneButton addTarget:self action:@selector(doneButton:)for controlEvents:UIControlEventTouchUpInside];
//定位键盘视图
int windowCount=[[UIApplication sharedApplication]windows]计数];
如果(windowCount<2){
返回;
}
UIWindow*tempWindow=[[UIApplication sharedApplication]windows]对象索引:1];
UIButton*donebtn=(UIButton*)[tempWindow viewWithTag:67123];
if(donebtn==nil)//避免根据我的要求反复添加(键盘上的上一个和下一个按钮)
[临时窗口添加子视图:self.doneButton];}
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];
        }
    }

}
if(windowCount<2){
返回;
}否则{
periodButton.frame=CGRectMake(0,[[UIScreen mainScreen]边界].size.height-53,106,53);
对于(在[[UIApplication sharedApplication]窗口]中的UIWindow*窗口){

如果([[window description]hasPrefix:@“此解决方案是否适用于所有情况。所有iPhone和所有iOS版本?当然,我的项目支持iOS 7+