【问题标题】:How to extend keyboard gradient on iPhone?如何在 iPhone 上扩展键盘渐变?
【发布时间】:2012-10-28 09:47:46
【问题描述】:

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

这里有 2 个例子。

Textastic & Prompt

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

他们是怎么做到的?扩展持有键盘或其他方式的 UIWindow?

用答案更新 1:

所以我使用了 Tyraz 编写的解决方案。

  1. 子类 UIToolbar
  2. 我使用 UIView 而不是图像,其背景颜色与键盘渐变的最终颜色相同,并使用 UIViewAutoResizingMaskFlexibleWidth 以便在旋转时覆盖键盘,高度为 3 像素

这是子类 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 以及我使用什么颜色进行着色的代码。

我使用以下代码将其添加到 viewDidLoad 中的 UITextView

    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;  

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

【问题讨论】:

  • 嗨阿马尔!我实际上希望增强我的输入附件视图(即 UIToolbar),使其具有与此处描述的相同的外观。您介意发布 separatorHideView 背景颜色的确切颜色设置吗?你是如何给 UIToolbar 上色的,让它有匹配的渐变来适应键盘?非常感谢!
  • 嗨内纳德。没问题。我不知道为什么上面的代码中没有显示颜色,但我会修复它。
  • 非常感谢!为我工作!

标签: iphone objective-c ios


【解决方案1】:

在 iOS 7 上,您可以创建 inputAccessoryView 以轻松匹配键盘样式:

[[UIInputView alloc] initWithFrame:<#frame#> 
                    inputViewStyle:UIInputViewStyleKeyboard];

【讨论】:

    【解决方案2】:

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

    将 inputAccessoryView 添加到键盘后(覆盖您的辅助 UIView 子类中的 didMoveToSuperview 方法以在发生这种情况时得到通知),将其添加到 inputAccessoryView 的超级视图中。

    在你的辅助 UIView 子类中应该是这样的:

    - (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 的框架,以防键盘的框架发生变化。

    【讨论】:

    • 这是解决问题的方法。我会用分析器更新问题。
    猜你喜欢
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多