尝试使用工具栏
override func viewDidAppear(animated: Bool) {
...
var toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.Default
toolBar.translucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
var nextButton = UIBarButtonItem(title: "Next", style: UIBarButtonItemStyle.Done, target: self, action: "nextTextfield")
var previousButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "previousTextfield")
var spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
toolBar.setItems([previousButton, spaceButton, nextButton], animated: false)
toolBar.userInteractionEnabled = true
toolBar.sizeToFit()
textField.delegate = self
textField.inputAccessoryView = toolBar
}
func nextTextfield() {
nextTextField.resignFirstResponder()
}
func previousTextfield() {
//if exist previous
//previousTextField.resignFirstResponder()
}
您正在键盘外添加手势来解除它。 –
我用过,但由于某些原因我不wana使用手势。因为当我使用手势时会禁用某些功能。 – Sahil
请删除“返回false”并尝试。 –