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

标签 ios keyboard ios7

我想要一个带有非透明键盘的键盘 - 我无法通过任何受支持的 UIKeyboardTypes 获得它。还有其他解决方法吗?

我想我可以用我想要的颜色在键盘下覆盖一个背景 View - 是否有一种好的方法可以使该背景 View 与键盘显示动画同步?

最佳答案

在 Xcode 5 中使用 iOS 7 的 Base SDK 编译应用程序时,iOS7 中的键盘是半透明的。
如果您改为在 Xcode 4.6.x 上构建应用程序,您将拥有像以前一样的非半透明键盘。
(我知道这是一个糟糕的解决方案,但尽管如此,我想我还是建议这样做)

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

  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 - 有没有办法在 iOS 7 中禁用键盘上的透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19035601/

相关文章:

iphone - 如何在 Ionic 3 中隐藏键盘?

ios7 - CMMotionActivityManager - 在应用程序暂停或在后台时接收运动事件更新

带有 Tabbar 的 iOS7 自动布局与 UIScrollView 和可缩放的 UIImageView 不工作

iphone - 只有 iOS 7 崩溃 [NSNull intValue] : unrecognized selector sent to instance

iphone - 将选择器上的分数格式化为最小公分母?

javascript - html5 视频无法在 Apple 机器上的 firefox 中播放

python - Selenium 。在弹出的新 chrome 打开文件上上传文件(或如何在 python 上模拟 ctrl+v)

objective-c - 如何正确链接自定义 UITableViewCell 和访问元素

ios - App Store Markdown 和更新信息

ubuntu - 如何在 Ubuntu 上的 PhpStorm 中使用 PHP 代码中的引号