<tfoot id='M6jrS'></tfoot>
<i id='M6jrS'><tr id='M6jrS'><dt id='M6jrS'><q id='M6jrS'><span id='M6jrS'><b id='M6jrS'><form id='M6jrS'><ins id='M6jrS'></ins><ul id='M6jrS'></ul><sub id='M6jrS'></sub></form><legend id='M6jrS'></legend><bdo id='M6jrS'><pre id='M6jrS'><center id='M6jrS'></center></pre></bdo></b><th id='M6jrS'></th></span></q></dt></tr></i><div id='M6jrS'><tfoot id='M6jrS'></tfoot><dl id='M6jrS'><fieldset id='M6jrS'></fieldset></dl></div>
      <bdo id='M6jrS'></bdo><ul id='M6jrS'></ul>

    1. <legend id='M6jrS'><style id='M6jrS'><dir id='M6jrS'><q id='M6jrS'></q></dir></style></legend>

        <small id='M6jrS'></small><noframes id='M6jrS'>

        如果我在 swift 中添加 UITapGestureRecognizer,则 UIButton 单击事件不起作用

        时间:2023-07-08
          • <bdo id='MoI7P'></bdo><ul id='MoI7P'></ul>
            • <tfoot id='MoI7P'></tfoot>

                <small id='MoI7P'></small><noframes id='MoI7P'>

                  <tbody id='MoI7P'></tbody>

                  <i id='MoI7P'><tr id='MoI7P'><dt id='MoI7P'><q id='MoI7P'><span id='MoI7P'><b id='MoI7P'><form id='MoI7P'><ins id='MoI7P'></ins><ul id='MoI7P'></ul><sub id='MoI7P'></sub></form><legend id='MoI7P'></legend><bdo id='MoI7P'><pre id='MoI7P'><center id='MoI7P'></center></pre></bdo></b><th id='MoI7P'></th></span></q></dt></tr></i><div id='MoI7P'><tfoot id='MoI7P'></tfoot><dl id='MoI7P'><fieldset id='MoI7P'></fieldset></dl></div>
                1. <legend id='MoI7P'><style id='MoI7P'><dir id='MoI7P'><q id='MoI7P'></q></dir></style></legend>
                  本文介绍了如果我在 swift 中添加 UITapGestureRecognizer,则 UIButton 单击事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的登录页面上,如果我专注于 UITextEdit 以输入电子邮件和密码,则会出现键盘并向上滚动登录页面.如果我触摸键盘外部,我会添加此代码以删除键盘.

                  On my login page, if I focus to UITextEdit for entering email and password, keyboard appears and login page scroll up. And I add this code for remove keyboard if I touch outside of keyboard.

                  extension UIViewController {
                      func hideKeyboardWhenTappedAround() {
                          let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
                          tap.cancelsTouchesInView = false
                          view.addGestureRecognizer(tap)
                      }
                      
                      @objc func dismissKeyboard() {
                          view.endEditing(true)
                          UIView.animate(withDuration: 0.3, animations: {
                              self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
                          })
                      }
                  }
                  

                  在我的 viewDidLoad() 函数中,我是这样添加的.

                  And on my viewDidLoad() function, I added it like this.

                  override func viewDidLoad() 
                  {
                          super.viewDidLoad()
                          //TODO
                          self.hideKeyboardWhenTappedAround()
                         ...
                  }
                  

                  效果很好,但是如果我在键盘仍然打开时单击登录按钮,dismisskeyboard() 函数可以工作,但 btnClick 函数不起作用.

                  It works well, But If I click login button when keyboard is still opening, dismisskeyboard() function works but btnClick function doesn't work.

                  @IBAction func LoginBtnClick(_ sender: Any) 
                  {
                          print("loginBtn")
                          //...
                  }
                  

                  我该如何解决这个问题?

                  How can I solve this problem?

                  推荐答案

                  不要在主viewController的视图中添加手势 在UIButton下面添加全屏子视图并添加手势

                  Don't add the gesture to main viewController's view add a full screen subview below UIButton and add the gesture to it

                  这篇关于如果我在 swift 中添加 UITapGestureRecognizer,则 UIButton 单击事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如果我们在真正的预提交处理程序中,由于 CA 限制,我们实际上不能添加任何新的栅栏——这可能意味着什么吗? 下一篇:触摸时淡出 UIButton

                  相关文章

                  • <bdo id='YriLm'></bdo><ul id='YriLm'></ul>
                2. <tfoot id='YriLm'></tfoot><legend id='YriLm'><style id='YriLm'><dir id='YriLm'><q id='YriLm'></q></dir></style></legend>
                  1. <i id='YriLm'><tr id='YriLm'><dt id='YriLm'><q id='YriLm'><span id='YriLm'><b id='YriLm'><form id='YriLm'><ins id='YriLm'></ins><ul id='YriLm'></ul><sub id='YriLm'></sub></form><legend id='YriLm'></legend><bdo id='YriLm'><pre id='YriLm'><center id='YriLm'></center></pre></bdo></b><th id='YriLm'></th></span></q></dt></tr></i><div id='YriLm'><tfoot id='YriLm'></tfoot><dl id='YriLm'><fieldset id='YriLm'></fieldset></dl></div>
                    1. <small id='YriLm'></small><noframes id='YriLm'>