UITextView's inputView on iOS 7

前端 未结 3 1566
栀梦
栀梦 2021-02-06 11:14

I\'m trying to create a custom keyboard for a UITextField, the background of this inputView should be transparent, I have set the background color in the view\'s xib file to \"c

3条回答
  •  灰色年华
    2021-02-06 11:49

    I am chasing the same issue, as I have a numeric keypad which fills only the left half of the screen in landscape mode (and is basically unusable on iOS7 where the blur effect covers the entire width of the screen). I haven't quite figured out how to get what I want (blurred background only behind my actual inputView), but I have figured out how to disable the blur entirely:

    1. Define a custom subclass of UIView and specify that in your xib file
    2. In this class override willMoveToSuperview: as follows

      - (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];
          }
      }
      

    This appears to impact the background of every custom inputView I have (but not the system keyboard) so you might need to save/restore whatever the normal opacity value is when your inputView gets removed from the superview if you don't want that.

提交回复
热议问题