iOS 7上的UITextView的inputView

mim*_*mim 6 iphone custom-controls uitextfield ios ios7

我正在尝试为UITextField创建自定义键盘,此inputView的背景应该是透明的,我已将视图的xib文件中的背景颜色设置为"clear color".它在iOS 6及更早版本上运行良好..但在iOS 7上它不起作用任何想法我怎样才能使它工作?我希望它完全透明

Jen*_*ult 5

这将在显示自定义键盘时将背景不透明度设置为零,并在显示普通键盘时将其重置为1.

+ (void)updateKeyboardBackground {
    UIView *peripheralHostView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] lastObject];

    UIView *backdropView;
    CustomKeyboard *customKeyboard;

    if ([peripheralHostView isKindOfClass:NSClassFromString(@"UIPeripheralHostView")]) {
        for (UIView *view in [peripheralHostView subviews]) {
            if ([view isKindOfClass:[CustomKeyboard class]]) {
                customKeyboard = (CustomKeyboard *)view;
            } else if ([view isKindOfClass:NSClassFromString(@"UIKBInputBackdropView")]) {
                backdropView = view;
            }
        }
    }

    if (customKeyboard && backdropView) {
        [[backdropView layer] setOpacity:0];
    } else if (backdropView) {
        [[backdropView layer] setOpacity:1];
    }
}

+ (void)keyboardWillShow {
    [self performSelector:@selector(updateKeyboardBackground) withObject:nil afterDelay:0];
}

+ (void)load {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}
Run Code Online (Sandbox Code Playgroud)


小智 0

我正在解决同样的问题,因为我有一个数字键盘,它在横向模式下仅填充屏幕的左半部分(并且在 iOS7 上基本上无法使用,其中模糊效果覆盖了屏幕的整个宽度)。我还没有完全弄清楚如何获得我想要的东西(仅在我的实际 inputView 后面模糊背景),但我已经弄清楚如何完全禁用模糊:

  1. 定义 UIView 的自定义子类并在 xib 文件中指定
  2. 在这个类中重写 willMoveToSuperview: 如下

    - (void)willMoveToSuperview:(UIView *)newSuperview
    {
        if (UIDevice.currentDevice.systemVersion.floatValue >= 7 &&
            newSuperview != nil)
        {
            CALayer *layer = newSuperview.layer;
            NSArray *subls = layer.sublayers;
            CALayer *blurLayer = [subls objectAtIndex:0];
            [blurLayer setOpacity:0];
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

这似乎会影响我拥有的每个自定义 inputView 的背景(但不会影响系统键盘),因此如果您不希望这样,当您的 inputView 从超级视图中删除时,您可能需要保存/恢复任何正常的不透明度值。