gpt4 book ai didi

ios - inputAccessoryView 未显示在键盘上方

转载 作者:行者123 更新时间:2023-11-28 11:14:36 25 4
gpt4 key购买 nike

Problem relates to this.我正在尝试使用我制作的自定义 View ,它有两个 TextField 输入和一个按钮,我使用 IB 它的 xib 制作它,我将它放在我的 Storyboard中并将它设置为在我的 View 底部.

当我想让 ContactInfoView 成为键盘的附属 View 时,问题就来了。

class ViewController: UIViewController, UITextViewDelegate {

@IBOutlet var cameraPreview: UIView!
@IBOutlet weak var ContactInfoView: KeyboardAccessoryView!



override func viewDidLoad() {
super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)





}
}

}


override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
//cameraPreviewLayer!.frame = cameraPreview.bounds

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillAppear"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide"), name: UIKeyboardWillHideNotification, object: nil)
ContactInfoView.NameInput.inputAccessoryView = ContactInfoView



}


override func viewDidDisappear(animated: Bool) {


super.viewDidDisappear(animated)


NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)


}

// keyboard stuff

var accessoryView = KeyboardAccessoryView(frame: CGRectZero);

override var inputAccessoryView: KeyboardAccessoryView {


return accessoryView

}

override func becomeFirstResponder() -> Bool {


return true
}

override func canBecomeFirstResponder() -> Bool {
return true
}


func keyboardWillAppear() {
print("Keyboard appeared")
}

func keyboardWillHide() {
print("Keyboard hidden")
}

}

ContactInfoView.NameInput.inputAccessoryView = ContactInfoView 没有将 View 放在键盘顶部。

我搞乱了代码,它开始因提供的链接而崩溃,但尝试该解决方案也没有用。

最佳答案

根据UITextView.h文件中的注释:

@property (nullable, readwrite, strong) UIView *inputView;             
@property (nullable, readwrite, strong) UIView *inputAccessoryView;

当对象成为第一响应者时呈现。如果设置为 nil,则恢复到以下响应者链。 如果在 first responder 时设置,在调用 reloadInputViews 之前不会生效。

您应该在设置 input.. 属性后调用 reloadInputViews 方法。

关于ios - inputAccessoryView 未显示在键盘上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32671989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com