iOS系统键盘Window层注意事项

划重点:UIRemoteKeyboardWindow是UITextEffectsWindow的子类

担心直接通过索引获取这两个window的安全性的小伙伴,可以通过遍历判断类名称来获取,这样对不同系统版本的适配性更强、更安全。但是要注意UIRemoteKeyboardWindow是UITextEffectsWindow的子类。

话不多说,上代码:

    NSString *version= [UIDevice currentDevice].systemVersion; 

    UIWindow *keyboardWindow;

    UIWindow *textEffectsWindow;

    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {

        if ([window isKindOfClass:NSClassFromString(@"UITextEffectsWindow")]) {

            if (version.doubleValue>=9.0) {

                if ([windowisKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")]) {

                    keyboardWindow = window;

                } else {

                    textEffectsWindow = window;

                }

            } else {

                textEffectsWindow = window;

            }

        }

    }

    if (keyboardWindow) {

        keyboardWindow.center = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.5f,[[UIScreen mainScreen] bounds].size.height*0.5f);

        keyboardWindow.bounds = CGRectMake(0,0, windowWidth, windowHeight);

        keyboardWindow.transform = CGAffineTransformMakeRotation(0);

    }

    if (textEffectsWindow) {

        textEffectsWindow.center = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.5f,[[UIScreen mainScreen] bounds].size.height*0.5f);

        textEffectsWindow.bounds = CGRectMake(0,0, windowWidth, windowHeight);

        textEffectsWindow.transform = CGAffineTransformMakeRotation(0);

    }

你可能感兴趣的:(iOS系统键盘Window层注意事项)