Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 标签贴在键盘上_Ios_Swift - Fatal编程技术网

Ios 标签贴在键盘上

Ios 标签贴在键盘上,ios,swift,Ios,Swift,如何使用“发送”按钮添加块,使其随键盘移动。这也是textview的表现 预览 设计块视图,然后将其底部约束附加为IBOutlet并执行此操作 override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSN

如何使用“发送”按钮添加块,使其随键盘移动。这也是textview的表现

预览


设计块视图,然后将其底部约束附加为IBOutlet并执行此操作

override func viewDidLoad() {
    super.viewDidLoad()            
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)    
}

@objc func keyboardWillShow(notification: NSNotification) {        
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {

        self.viewBotCon.constant = -1 * keyboardSize.height

        self.view.layoutIfNeeded()

    }        
}

@objc func keyboardWillHide(notification: NSNotification) {

      self.viewBotCon.constant = 0

      self.view.layoutIfNeeded()
}

在控制器中添加此代码

func createInputAccessoryView () -> UIToolbar {

        let toolbarAccessoryView = UIToolbar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: 44))
        toolbarAccessoryView.barStyle = .default
        toolbarAccessoryView.tintColor = UIColor.blue
        let flexSpace = UIBarButtonItem(barButtonSystemItem:.flexibleSpace, target:nil, action:nil)
        let doneButton = UIBarButtonItem(barButtonSystemItem:.done, target:self, action:Selector(("doneTouched")))
        toolbarAccessoryView.setItems([flexSpace, doneButton], animated: false)

        return toolbarAccessoryView
    }

    @objc func doneTouched() {
        /* Your action goes here */
    }
现在将其添加到viewDidLoad或任何位置

yourTextView.inputAccessoryView = createInputAccessoryView ()

send buton-它是您的工具栏或其他工具最后一行给出:表达式解析为未使用的l值