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

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

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

        当用户将手指拖入按钮区域时触发 UIButton 的方法?

        时间:2023-07-06

        <small id='6cx2u'></small><noframes id='6cx2u'>

        <legend id='6cx2u'><style id='6cx2u'><dir id='6cx2u'><q id='6cx2u'></q></dir></style></legend>

          1. <tfoot id='6cx2u'></tfoot>
                <tbody id='6cx2u'></tbody>

              <i id='6cx2u'><tr id='6cx2u'><dt id='6cx2u'><q id='6cx2u'><span id='6cx2u'><b id='6cx2u'><form id='6cx2u'><ins id='6cx2u'></ins><ul id='6cx2u'></ul><sub id='6cx2u'></sub></form><legend id='6cx2u'></legend><bdo id='6cx2u'><pre id='6cx2u'><center id='6cx2u'></center></pre></bdo></b><th id='6cx2u'></th></span></q></dt></tr></i><div id='6cx2u'><tfoot id='6cx2u'></tfoot><dl id='6cx2u'><fieldset id='6cx2u'></fieldset></dl></div>
                <bdo id='6cx2u'></bdo><ul id='6cx2u'></ul>
                • 本文介绍了当用户将手指拖入按钮区域时触发 UIButton 的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要一个在以下条件下触发其方法的按钮:

                  • 当用户点击按钮时
                  • 当用户按下按钮并将他/她的手指拖出按钮区域时
                  • 当用户将手指从按钮区域外拖到按钮区域内时

                  基本上,无论何时触摸按钮的任何部分,无论触摸的来源如何,我都希望触发该方法,但希望通过操作 UIButton 属性来完成此操作,如 touchedUpInside 等.p>

                  感谢您的建议!

                  解决方案

                  关于:

                  <块引用>
                  • 当用户按下按钮并将他/她的手指拖出按钮区域时

                  我最近做了类似的事情.这是我在 Swift 中的代码.

                  (在本例中,您继承了 UIButton,例如:class FadingButton: UIButton)

                  <代码>...//用户点击按钮,然后移动手指.覆盖 func touchesMoved(_ touches: Set, with event: UIEvent?) {super.touchesMoved(touches, with: event)//获取手指移动到的点if let point: CGPoint = touches.first?.location(in: self) {//如果手指被拖到按钮之外...if ((point.x <0 || point.x > bounds.width) ||(point.y < 0 || point.y > bounds.height)) {//在这里做任何你需要的事情}}}...

                  我希望它对某人有所帮助.

                  I want to have a button that triggers its method under the following conditions:

                  • When the user taps the button
                  • When the user presses the button and drags his/her finger out of the button's area
                  • When the user drags his/her finger from outside the button's area to inside the button's area

                  Basically, anytime any part of the button is touched, regardless of origin of touch, I want the method triggered, but want to accomplish this by manipulating UIButton properties, like touchedUpInside and such.

                  Thanks for the suggestions!

                  解决方案

                  Regarding:

                  • When the user presses the button and drags his/her finger out of the button's area

                  I recently have done something similar. Here is my code in Swift.

                  (In this example you subclassed UIButton, like: class FadingButton: UIButton)

                  ...
                  
                  // The user tapped the button and then moved the finger around.
                  override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
                      super.touchesMoved(touches, with: event)
                  
                      // Get the point to which the finger moved
                      if let point: CGPoint = touches.first?.location(in: self) {
                  
                          // If the finger was dragged outside of the button...
                          if ((point.x < 0 || point.x > bounds.width) ||
                              (point.y < 0 || point.y > bounds.height)) {
                  
                              // Do whatever you need here
                          }
                      }
                  }
                  ...
                  

                  I hope it helps someone.

                  这篇关于当用户将手指拖入按钮区域时触发 UIButton 的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我可以为 UIButton 使用 UIBarButtonSystemItem 吗? 下一篇:将发件人作为 id 或特定类转换为 IBAction

                  相关文章

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

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

                    <legend id='GzIht'><style id='GzIht'><dir id='GzIht'><q id='GzIht'></q></dir></style></legend>
                    <tfoot id='GzIht'></tfoot>