iOS小技巧

最近开始记录下自己开发遇到的问题,如果解决了就会记录下来,以便自己日后回顾工作。

测试妹子给我提了一个问题是视图遮挡了,我一看,确实会遮挡,我就加了下面的这段代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- (UIView*)keyboardView
{
    NSArray * windows = [[UIApplication sharedApplication] windows];
    for (UIWindow * window in [windows reverseObjectEnumerator])
    {
        for (UIView * view in [window subviews])
        {
            // UIPeripheralHostView is used from iOS 4.0, UIKeyboard was used in previous versions,UIInputSetContainerView was used iOS 8.0
            if (!strcmp(object_getClassName(view), "UIPeripheralHostView") || !strcmp(object_getClassName(view), "UIKeyboard") ||
                !strcmp(object_getClassName(view), "UIInputSetContainerView"))
            {
                return view;
            }
        }
    }
    return nil;
}

- (UIView*)keyboardViewForView:(UIView *)view
{
    UIView * keyboardView = [self keyboardView];
    if (keyboardView) {
        view = keyboardView.superview;
    }
    return view;
}
这样我们在调用下面的方法keyboardViewForView就能显示出来了。问题得到了解决。

Comments