如何将inputAccessoryView添加到自定义键盘(ios扩展)

问题描述:

我已经通过编程创建了自定义键盘。没有故事板。我想按照Apple自己的键盘添加上面的附件视图。无法弄清楚如何在我的应用程序中的我的键盘文件中的swift中执行此操作。如何将inputAccessoryView添加到自定义键盘(ios扩展)

我试过(0行是一个UIView):

self.view.inputAccessoryView?.addSubview(row0) 

谢谢!

您不要在自定义键盘中执行此操作 - inputAccessoryView是应用程序本身(控制输入文本的文本字段的控件)添加到键盘正在使用的上方。如果您需要更高的键盘高度,可以使用此代码(复制自Apple的App Extension Programming Guide):

CGFloat _expandedHeight = 500; // this is the height you want your keyboard to be 
NSLayoutConstraint *_heightConstraint = 
    [NSLayoutConstraint constraintWithItem: self.view 
           attribute: NSLayoutAttributeHeight 
           relatedBy: NSLayoutRelationEqual 
            toItem: nil 
           attribute: NSLayoutAttributeNotAnAttribute 
           multiplier: 0.0 
            constant: _expandedHeight]; 
[self.view addConstraint: _heightConstraint]; 
+0

谢谢。这就说得通了。 – jasonjasonfried 2014-10-02 22:15:43

+0

你好,我使用你的代码,但不增加customkeyboard的高度。 – 2015-01-05 07:20:37

+0

那么如何激活inputAccessoryView?使用系统键盘,inputaccessoryview似乎工作,但与我的自定义键盘,我看不到任何界面来激活inputaccessoryview – LKM 2016-08-06 16:40:40