GVKun编程网logo

使用InputAccessoryView swift在键盘顶部添加视图(swift键盘输入)

1

如果您想了解使用InputAccessoryViewswift在键盘顶部添加视图和swift键盘输入的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用InputAccessoryViewswif

如果您想了解使用InputAccessoryView swift在键盘顶部添加视图swift键盘输入的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用InputAccessoryView swift在键盘顶部添加视图的各个方面,并为您解答swift键盘输入的疑在这篇文章中,我们将为您介绍使用InputAccessoryView swift在键盘顶部添加视图的相关知识,同时也会详细的解释swift键盘输入的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

使用InputAccessoryView swift在键盘顶部添加视图(swift键盘输入)

使用InputAccessoryView swift在键盘顶部添加视图(swift键盘输入)

我试图将uiview始终添加到键盘顶部。我首先使用KeyboardWillShow /
Hide做到了这一点,但是它并没有涵盖所有情况,因此我尝试使用inputAccesoryView。这是我尝试的:

private var accessoryView = UIView(frame: CGRectZero)class ViewController : UIViewController {var myView: customUIViewoverride var inputAccessoryView: UIView {    return accessoryView}override func canBecomeFirstResponder() -> Bool {    return true}override func viewDidLoad() {   super.viewDidLoad()   accessoryView = myView}}

我收到以下错误:

由于未捕获的异常“
UIViewControllerHierarchyInconsistencyency”而终止应用程序,原因:“子视图控制器:UICompatibilityInputViewController应该具有父视图控制器:MyViewController,但请求的父对象是:UIInputWindowController:”

任何帮助将不胜感激!

答案1

小编典典

为了使视图停留在键盘上方,代码本身非常简单。您发布的代码不正确,请尝试以下操作(请注意,您必须连接textFieldUITextField情节提要中的):

@IBOutlet weak var textField: UITextField!override func viewDidLoad() {    super.viewDidLoad()    let customView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 44))    customView.backgroundColor = UIColor.red    textField.inputAccessoryView = customView}

CLInputAccessoryView iOS 键盘视图

CLInputAccessoryView iOS 键盘视图

CLInputAccessoryView 介绍

CLInputAccessoryView 是点击输入框后,为弹出键盘添加上方的工具条。

image

使用方法:

#import "CLInputAccessoryView.h"
  // 初始化键盘上方工具栏
_inputAccessoryView = [[CLInputAccessoryView alloc] init];
[_inputAccessoryView addControlledTextView:_textField];
[_inputAccessoryView addControlledTextView:_textView];
_inputAccessoryView.leftButtonColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
// 如果点击按钮后只隐藏键盘,则不用添加委托,否则添加协议和委托
为使用类添加协议 <CLInputAccessoryViewDelegete>
_inputAccessoryView.delegate = self;
/** 点击左侧按钮后调用此方法,返回YES则隐藏键盘,NO则不隐藏键盘 */
- (BOOL)leftButtonDidClick:(id)textView
{
    Nsstring *text = [textView text];
    [textView setText:[text stringByAppendingString:@"取消 "]];
    return YES;
}
/** 点击右侧按钮后触发此方法 */
- (BOOL)rightButtonDidClick:(id)textView
{
    Nsstring *text = [textView text];
    [textView setText:[text stringByAppendingString:@"完成 "]];
    return NO;
}

CLInputAccessoryView 官网

https://github.com/changelee82/CLInputAccessoryView

DMFormInputAccessoryView

DMFormInputAccessoryView

DMFormInputAccessoryView 介绍

DMFormInputAccessoryView 是一个简单的用于输入表单中的键盘控件。

DMFormInputAccessoryView 官网

https://github.com/fumoboy007/DMFormInputAccessoryView

inputAccessoryView 自定义键盘

inputAccessoryView 自定义键盘

inputAccessoryView:

UITextFields and UITextViews have an inputAccessoryView property, which you can set to any view, that is automatically displayed above and animated with the keyboard.

Note that the view you use should neither be in the view hierarchy elsewhere, nor should you add it to some superview, this is done for you.

翻译:
UITextFields和UITextView有一个inputAccessoryView的属性,当你想在键盘上展示一个自定义的view时,你就可以设置该属性。你设置的view就会自动和键盘keyboard一起显示了。

需要注意的是,你所自定义的view既不应该处在其他的视图层里,也不应该成为其他视图的子视图。其实也就是说,你所自定义的view只需要赋给属性inputAccessoryView就可以了,不要再做其他多余的操作。


例子:

其中短信发送页的键盘上的那个输入的框就是利用这个属性做的,你可以尝试一下,很简单的哦。


iOS UITest:如何找到UITableViewCell的AccessoryView?

iOS UITest:如何找到UITableViewCell的AccessoryView?

你好我现在正在学习UITests

我有个问题

如何在tableViewCell上检测accessoryView的点击?在UITest

下面是我的tableViewCell

enter image description here

我想检测细节关闭配件视图的点击

像这样

app.tables.cells.buttons [ “FTCellAccesoryIdentifier”].轻按()

但是accesorry是UIView的子类

所以我在cellForRows函数中分配accisibility identifier键

cell.accessoryView?.accessibilityIdentifier =“FTCellAccesoryIdentifier”

我的测试功能是

我试试

app.tables.cells.elementBoundByIndex(lastCellIndex).otherElements.elementMatchingType(.Any,identifier: "FTCellAccesoryIdentifier").tap()

但不行

可以在UITests中点击单元格的accesoryView吗?

解决方法

TL; DR

关于…

is possible to tap cell’s accesoryView in UITests?

……是的
但是你必须使用默认的可访问性标识符.
例如,对于像这样的单元格:

enter image description here

在UI测试期间点击详细信息披露按钮(“更多信息”是此处的关键):

XCUIApplication().tables.buttons["More Info,Title"].tap()

在UI测试期间点击单元格本身:

XCUIApplication().tables.staticTexts["Title"].tap()

很长的故事:

无法更改详细信息披露的默认辅助功能标识符. From Apple:

Note: If your table cells contain any of the standard table-view elements,such as the disclosure indicator,detail disclosure button,
or delete control,you do not have to do anything to make these
elements accessible. If,however,your table cells include other types
of controls,such as a switch or a slider,you need to make sure that
these elements are appropriately accessible.

当您尝试在cellForRow中设置Detail disclosure的可访问性标识符/标签时,cell.accessoryView为nil.为什么?从Apple开始:

accessoryView的

讨论

If the value of this property is not nil,the UITableViewCell class
uses the given view for the accessory view in the table view’s normal
(default) state; it ignores the value of the accessoryType property.
The provided accessory view can be a framework-provided control or
label or a custom view. The accessory view appears in the the right
side of the cell.

在您定义附件视图之前,附件视图将为零. :/

如果您真的想为它设置自定义标识符,则需要提供“自己的”详细信息披露(例如:定制的UIView).例如(说明):

cell.accessoryView = UIView(frame: CGRectMake(0,20,20))
cell.accessoryView?.backgroundColor = UIColor.blueColor()
cell.accessoryView?.accessibilityIdentifier = "FTCellAccesoryIdentifier"

关于使用InputAccessoryView swift在键盘顶部添加视图swift键盘输入的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于CLInputAccessoryView iOS 键盘视图、DMFormInputAccessoryView、inputAccessoryView 自定义键盘、iOS UITest:如何找到UITableViewCell的AccessoryView?等相关知识的信息别忘了在本站进行查找喔。

本文标签: