显示键盘和移动框架后,UILabel上的Tap Gesture停止工作

时间:2015-06-22 05:44:44

标签: ios swift uilabel uitextview

我有UITextView以及UILabel提交按钮,该按钮固定在我的视图底部。当用户按下UITextView时,我添加了一个键盘监听器来移动键盘框架并将UILabel向上移动到键盘上方。问题是Tap 手势识别器会在键盘出现时立即停止识别水龙头。在此之前它完美无缺。寻求有关如何修复的帮助。

这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    var center: NSNotificationCenter = NSNotificationCenter.defaultCenter()
    center.addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
    center.addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)

    //Comments TextView
    var commentText = UITextView(frame: CGRectMake(5,5,self.view.frame.width * 0.65, 30))
    commentText.backgroundColor = UIColor.lightGrayColor()
    commentText.textColor = UIColor.darkGrayColor()
    commentText.editable = true
    commentText.text = "Write a Comment..."
    mainSV.addSubview(commentText)

    //Submit button
    var submitTF = UILabel(frame:CGRectMake(commentText.frame.maxX, 0, self.view.frame.width - commentText.frame.maxX - 30, 30))
    submitTF.text = "Send"
    submitTF.textAlignment = NSTextAlignment.Right
    submitTF.enabled = false
    submitTF.userInteractionEnabled = true

    var tap = UITapGestureRecognizer(target:self, action:Selector("submitTap:"))
    submitTF.addGestureRecognizer(tap)
}


func keyboardWillShow(notification: NSNotification) {
    commentText.text=""
    self.view.frame = CGRectMake(0,-150,320,460)
}

0 个答案:

没有答案