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

Is there a way to disable transparency on the keyboard in iOS 7?(有没有办法在 iOS 7 中禁用键盘上的透明度?)
本文介绍了有没有办法在 iOS 7 中禁用键盘上的透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想要一个带有非透明键盘的键盘 - 我无法使用任何受支持的 UIKeyboardTypes 来实现.有没有其他办法解决这个问题?

I would like to have a keyboard with a non-transparent keyboard - I couldn't get this with any of the supported UIKeyboardTypes. Is there another way around this?

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

I suppose I could just overlay a background view under the keyboard with the color I want - would there be a good way to animate that background view in sync with the keyboard show animation?

推荐答案

在 Xcode 5 中使用 iOS 7 的 Base SDK 编译应用时,iOS7 中的键盘是半透明的.
如果您在 Xcode 4.6.x 上构建应用程序,您将像以前一样拥有非半透明键盘.
(我知道这是一个糟糕的修复,但我想我会建议它)

The keyboard in iOS7 is translucent when app is compiled in Xcode 5 with a Base SDK of iOS 7.
If you build the app on Xcode 4.6.x instead, you'll have the non-translucent keyboard as before.
(i know this is a shitty fix but nonetheless, i thought i'd suggest it)

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

anyways, you could alternatively try making use of the default keyboard notifications:

  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 中禁用键盘上的透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Pywin32 (com objects) on Mac(Mac 上的 Pywin32(com 对象))
convert big yml data(转换大 yml 数据)
View aligned to top of keyboard appears in wrong place in iOS 9 Shortcut Bar only mode(在 iOS 9 Shortcut Bar only 模式下,与键盘顶部对齐的视图出现在错误的位置)
Disable speech to text button (Micro phone) on soft input keyboard in android programmatically(以编程方式在android中的软输入键盘上禁用语音到文本按钮(麦克风))
UIkeyboard type(UI键盘类型)
Android - customized keyboard key and action(Android - 自定义键盘按键和操作)