UITextView键盘正在打开2个点击。

时间:2015-10-23 15:38:13

标签: swift keyboard uitextview xcode7

我有一个带有标签的UITextView作为占位符。当用户点击UITextView时,标签消失,但是为了显示键盘,需要另外2次点击。当我移除隐藏标签的水龙头手势时,键盘完美运行。这是我的代码任何关于问题是什么的想法???

var tapTerm:UITapGestureRecognizer = UITapGestureRecognizer()



 override func viewDidLoad() {
    super.viewDidLoad()

    bioTextfield.delegate = self



    tapTerm = UITapGestureRecognizer(target: self, action: "tapTextView:")
    // bioPlaceholderLabel.addGestureRecognizer(tapTerm)
    bioTextfield.addGestureRecognizer(tapTerm)
        }


func tapTextView(sender:UITapGestureRecognizer) {
    // hide placeholder label text
    bioPlaceholderLabel.text = ""

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}



// when user touches outside the keyboard close the keyboard


 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {


    self.view.endEditing(true)

}

// when user presses the return button close the keyboard

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if text == "\n" {
        textView.resignFirstResponder()
        return false
    }
    return true
}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

更简单的方法是,您应该使用此自定义UITextView(带占位符):KMPlaceholderTextView。我正在使用,太棒了。