如何在iPhone上扩展键盘渐变? [英] How to extend keyboard gradient on iPhone?

查看:147
本文介绍了如何在iPhone上扩展键盘渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很少有应用程序在扩展键盘,但我想知道他们是如何做到的。

I see that few apps are extending keyboard but I would like to know how they do it.

以下是2个例子。

Textastic &
提示

现在我知道我可以将inputAccessoryView添加到UITextView,但它仍然有一条细线,将键盘与UIToolbar分开,如图所示。

Now I know that I can add inputAccessoryView to UITextView but it still has small thin line that separates keyboard from UIToolbar like on image bellow.

他们是如何做到的?扩展保存键盘的UIWindow还是以其他方式?

How they do it? Extending UIWindow that holds keyboard or in some other way?

更新1并回答:

所以我用过Tyraz写的解决方案。

So I have used solution that Tyraz wrote.


  1. 子类UIToolbar

  2. 而不是图像我使用了背景颜色的UIView与键盘渐变的整理颜色相同,并使用UIViewAutoResizingMaskFlexibleWidth,以便在旋转时覆盖键盘,高度为3像素

这是用于子类的UIToolbar代码

Here is the code for the subclassed UIToolbar

- (void)didMoveToSuperview {

    [self.separatorHideView removeFromSuperview];

    CGRect seperatorRect = CGRectMake(self.frame.origin.x,
                                      self.frame.size.height,
                                      self.frame.size.width,
                                      3.0);

    self.separatorHideView = [[UIView alloc]];
    self.separatorHideView.backgroundColor = [UIColor colorWithRed:0.569 green:0.600 blue:0.643 alpha:1.000];
    self.separatorHideView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self addSubview:self.separatorHideView];
}

更新2:这是代码我是如何将它添加到UITextView的颜色我用于色调。

Update 2: Here is code how I'm adding it to UITextView and what color I'm using for tint.

我将它添加到viewDidLoad中的UITextView,代码如下

I'm adding it to the UITextView in viewDidLoad with following code

    CustomToolbar *accessoryToolbar = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 38)];
    accessoryToolbar.tintColor = [UIColor colorWithRed:0.569 green:0.600 blue:0.643 alpha:1.000];
    editor.inputAccessoryView = accessoryToolbar;  

这就是应用解决方案的样子

And this is how it looks like with solution applied to it

推荐答案

我会尝试使用inputAccessoryView加上第二个位于分隔线顶部并填补空白的视图。

I would try to use a inputAccessoryView plus a second view that sits on top of the separator line and "fills the gap".

一旦inputAccessoryView被添加到键盘(覆盖在你的附件UIView子类的didMoveToSuperview方法时发生这种情况时的通知),将其添加到inputAccessoryView的上海华。

Once the inputAccessoryView is added to the keyboard (overwrite the didMoveToSuperview method in your accessory UIView subclass to get notified when this happens), add it to the inputAccessoryView's superview.

应该是这样的,在你的附件UIView子类:

Should be something like that in your accessory UIView subclass:

- (void)didMoveToSuperview {
  [self.separatorHideView removeFromSuperview];

  CGRect seperatorRect = CGRectMake(self.frame.origin.x, 
                                    self.frame.origin.y + self.frame.size.height,
                                    self.frame.size.width,
                                    2.0);

  UIImage *gapGradient = [UIImage imageNamed:@"GapGradient"];
  self.separatorHideView = [[UIImageView alloc]initWithImage:gapGradient];
  self.separatorHideView.frame = seperatorRect;

  [self.superview addSubview:self.separatorHideView];
}

我还会覆盖你的附件UIView子类中的setFrame来更新框架gapView以防键盘的框架被更改。

I would also overwrite setFrame in your accessory UIView subclass to update the frame of the gapView in case the frame of the keyboard is changed.

这篇关于如何在iPhone上扩展键盘渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆