“完成"按钮在数字键盘iOS 9问题中不可见 [英] done button is not visible in number pad iOS 9 issue

查看:70
本文介绍了“完成"按钮在数字键盘iOS 9问题中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在ios 6,7,8中运行,但是在ios 9中调用了all方法,但此方法不可见.在数字键盘上.这是我的代码.

this code is working in ios 6,7,8 but this all method is called in ios 9 but it is not visible. on number pad. here is my code.

#import "ViewController.h"
#define TAG_BUTTON_DONE 67125
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)keyboardDidShow:(NSNotification *)note {
    [self addButtonToKeyboard];
}
- (void)addButtonToKeyboard{
    //NSLog(@"addButtonToKeyboard");
    //jenish



    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        // create custom button
        UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
        doneButton.frame = CGRectMake(0, 163, 106, 53);
        doneButton.adjustsImageWhenHighlighted = NO;
        [doneButton setTag:TAG_BUTTON_DONE];
        //[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
        //[doneButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
        [doneButton setTitle:@"Done" forState:UIControlStateNormal];
        [doneButton setTintColor:[UIColor blackColor]];
        [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

        // locate keyboard view
        int windowCount = (int)[[[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){
                [keyboard addSubview:doneButton];
            }
            else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES){
                for(int j = 0 ; j < [keyboard.subviews count] ; j++) {
                    UIView* hostkeyboard = [keyboard.subviews objectAtIndex:j];
                    if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES){
                        [hostkeyboard addSubview:doneButton ];
                        [hostkeyboard bringSubviewToFront:doneButton];

                    }
                }
            }
            else
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [keyboard addSubview:doneButton];
                });


            }
        }
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject];
    if(touch.phase == UITouchPhaseBegan) {
        [self.tf resignFirstResponder];
    }
}
@end

然后,您需要进入背景并站在地面上,它会比隐藏隐藏几秒钟.请帮我. 谢谢

then you need to go background and come on fore ground it will visible for few second than it will go hide. please help me. thank you

推荐答案

更改

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

收件人:

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] lastObject];

这篇关于“完成"按钮在数字键盘iOS 9问题中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆