有没有办法在iOS 7禁用键盘上的透明度?

我想有一个不透明的键盘键盘 – 我不能得到任何支持的UIKeyboardTypes这个。 有没有其他的方法呢?

我想我可以叠加在我想要的颜色与键盘下的背景视图 – 是否有一个好的方法来animation与键盘显示animation同步的背景视图?

iOS7中的键盘在Xcode 5中使用iOS 7的基本SDK进行编译时是半透明的。
如果您在Xcode 4.6.x上构build应用程序,则会像以前那样使用非半透明键盘。
(我知道这是一个糟糕的解决方法,但是,我想我会build议它)

无论如何,你也可以尝试使用默认的键盘通知:

  1. UIKeyboardWillShowNotification
  2. UIKeyboardWillHideNotification

应该像这样:

 -(void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } -(void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } 

 -(void)keyboardWillShow:(NSNotification *)note { /* Would have used: CGRect rectStart = [note.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue]; CGRect rectEnd = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; Reason for not using: The above two keys are not being used although, ideally, they should have been since they seem to be buggy when app is in landscape mode Resolution: Using the deprecated UIKeyboardBoundsUserInfoKey since it works more efficiently */ CGRect rectStart_PROPER = [note.userInfo[UIKeyboardBoundsUserInfoKey] CGRectValue]; rectStart_PROPER.origin.y = self.view.frame.size.height; UIView *vwUnderlay = [self.view viewWithTag:8080]; if (vwUnderlay) { [vwUnderlay removeFromSuperview]; } vwUnderlay = [[UIView alloc] init]; [vwUnderlay setFrame:rectStart_PROPER]; [vwUnderlay setBackgroundColor:[UIColor orangeColor]]; [vwUnderlay setTag:8080]; [self.view addSubview:vwUnderlay]; [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] delay:0 options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16 animations:^{ [vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, -vwUnderlay.frame.size.height)]; } completion:nil]; } 

 -(void)keyboardWillHide:(NSNotification *)note { UIView *vwUnderlay = [self.view viewWithTag:8080]; [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] delay:0 options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16 animations:^{ [vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, vwUnderlay.frame.size.height)]; } completion:^(BOOL finished){ [vwUnderlay removeFromSuperview]; }]; } 

苹果不允许任何人修改默认的键盘。 如果你打算使用iOS 7,那么你将不得不处理半透明的键盘。

我能想到的唯一方法就是devise自己的键盘,但这是一个乏味的过程。

我今天正在看同样的事情,我发现一个简单的解决方法(虽然,还不知道它是多么可靠)。

为了工作,我为我的键盘控件( UITextViewUITextField )设置了一个inputAccessoryView 。 在我设置为inputAccessoryViewUIView类中,我添加了以下内容:

 -(void)layoutSubviews{ [super layoutSubviews]; frame = _lKeyboardBackground.frame; frame.origin.y = [self convertPoint:self.frame.origin toView:self.superview].y+self.frame.size.height; frame.size.width = self.bounds.size.width; frame.origin.x = 0; frame.size.height = 500; _lKeyboardBackground.frame = frame; [self refreshKeyboardBackground]; } -(void)didMoveToSuperview{ [super didMoveToSuperview]; if (self.superview) { [self.superview.layer insertSublayer:_lKeyboardBackground atIndex:lMagicLayerIndex]; } else { [_lKeyboardBackground removeFromSuperlayer]; } } -(void)setFrame:(CGRect)frame{ [super setFrame:frame]; [self refreshKeyboardBackground]; // setFrame: is called when keyboard changes (eg: to a custom input view) } -(void)refreshKeyboardBackground{ if (_lKeyboardBackground.superlayer) { CALayer *parent = _lKeyboardBackground.superlayer; [_lKeyboardBackground removeFromSuperlayer]; [parent insertSublayer:_lKeyboardBackground atIndex:lMagicLayerIndex]; } } 

_lKeyboardBackground是我在init方法中设置的一个CALayer

 _lKeyboardBackground = [CALayer layer]; _lKeyboardBackground.backgroundColor = [[UIColor redColor] CGColor]; //or some less annoying color 

这理论上应该通过苹果的批准,但我从来没有testing过。 还有很多改变,这在以后的版本或其他一些情况下是不行的(例如,当iPad上有分离的键盘时)

我使用的lMagicLayerIndex是1,它给出了绝对的颜色。
请注意,关键帧中仍然可以注意到模糊。

使用键盘通知来显示/隐藏键盘后面的自定义黑色视图(如果使用白色键盘,则显示为白色),并且不再透明。