<bdo id='mhxjj'></bdo><ul id='mhxjj'></ul>
    1. <tfoot id='mhxjj'></tfoot>
    2. <legend id='mhxjj'><style id='mhxjj'><dir id='mhxjj'><q id='mhxjj'></q></dir></style></legend>
    3. <small id='mhxjj'></small><noframes id='mhxjj'>

        <i id='mhxjj'><tr id='mhxjj'><dt id='mhxjj'><q id='mhxjj'><span id='mhxjj'><b id='mhxjj'><form id='mhxjj'><ins id='mhxjj'></ins><ul id='mhxjj'></ul><sub id='mhxjj'></sub></form><legend id='mhxjj'></legend><bdo id='mhxjj'><pre id='mhxjj'><center id='mhxjj'></center></pre></bdo></b><th id='mhxjj'></th></span></q></dt></tr></i><div id='mhxjj'><tfoot id='mhxjj'></tfoot><dl id='mhxjj'><fieldset id='mhxjj'></fieldset></dl></div>
      1. 具有单按和长按事件的 UIButton 快速

        时间:2023-07-08
        <i id='WcurZ'><tr id='WcurZ'><dt id='WcurZ'><q id='WcurZ'><span id='WcurZ'><b id='WcurZ'><form id='WcurZ'><ins id='WcurZ'></ins><ul id='WcurZ'></ul><sub id='WcurZ'></sub></form><legend id='WcurZ'></legend><bdo id='WcurZ'><pre id='WcurZ'><center id='WcurZ'></center></pre></bdo></b><th id='WcurZ'></th></span></q></dt></tr></i><div id='WcurZ'><tfoot id='WcurZ'></tfoot><dl id='WcurZ'><fieldset id='WcurZ'></fieldset></dl></div>
          <tfoot id='WcurZ'></tfoot>

          • <bdo id='WcurZ'></bdo><ul id='WcurZ'></ul>

            • <legend id='WcurZ'><style id='WcurZ'><dir id='WcurZ'><q id='WcurZ'></q></dir></style></legend>

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

                    <tbody id='WcurZ'></tbody>
                  本文介绍了具有单按和长按事件的 UIButton 快速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 button clickbutton long click 上触发两个动作.我在界面生成器中添加了一个 UIbutton.我如何使用 IBAction 触发两个动作有人可以告诉我如何存档吗?

                  I want to trigger two action on button click and button long click. I have add a UIbutton in my interface builder. How can i trigger two action using IBAction can somebody tell me how to archive this ?

                  这是我用来点击按钮的代码

                  this is the code i have used for a button click

                  @IBAction func buttonPressed (sender: UIButton) {……}

                  我可以使用这种方法还是必须使用其他方法进行长按?

                  can i use this method or do i have to use another method for long click ?

                  推荐答案

                  如果您想通过单击执行任何操作并长按您可以通过这种方式将手势添加到按钮中:

                  If you want to perform any action with single tap you and long press the you can add gestures into button this way:

                  @IBOutlet weak var btn: UIButton!
                  
                  override func viewDidLoad() {
                  
                      let tapGesture = UITapGestureRecognizer(target: self, #selector (tap))  //Tap function will call when user tap on button
                      let longGesture = UILongPressGestureRecognizer(target: self, #selector(long))  //Long function will call when user long press on button.
                      tapGesture.numberOfTapsRequired = 1
                      btn.addGestureRecognizer(tapGesture)
                      btn.addGestureRecognizer(longGesture)
                  }
                  
                  @objc func tap() {
                  
                      print("Tap happend")
                  }
                  
                  @objc func long() {
                  
                      print("Long press")
                  }
                  

                  这样你可以为单个按钮添加多个方法,你只需要那个按钮的 Outlet ..

                  This way you can add multiple method for single button and you just need Outlet for that button for that..

                  这篇关于具有单按和长按事件的 UIButton 快速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:自定义 UITableView 中的删除按钮 下一篇:UIbutton标题上的自定义字体夹在单词的顶部

                  相关文章

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

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

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

                        <bdo id='Yw8os'></bdo><ul id='Yw8os'></ul>