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

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

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

    2. <legend id='PVGRJ'><style id='PVGRJ'><dir id='PVGRJ'><q id='PVGRJ'></q></dir></style></legend>

        Swift,对于某些 UIViews 到他们的整体控制器单击时

        时间:2023-09-12
        1. <tfoot id='vhUiN'></tfoot>
        2. <i id='vhUiN'><tr id='vhUiN'><dt id='vhUiN'><q id='vhUiN'><span id='vhUiN'><b id='vhUiN'><form id='vhUiN'><ins id='vhUiN'></ins><ul id='vhUiN'></ul><sub id='vhUiN'></sub></form><legend id='vhUiN'></legend><bdo id='vhUiN'><pre id='vhUiN'><center id='vhUiN'></center></pre></bdo></b><th id='vhUiN'></th></span></q></dt></tr></i><div id='vhUiN'><tfoot id='vhUiN'></tfoot><dl id='vhUiN'><fieldset id='vhUiN'></fieldset></dl></div>

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

            <tbody id='vhUiN'></tbody>
            <legend id='vhUiN'><style id='vhUiN'><dir id='vhUiN'><q id='vhUiN'></q></dir></style></legend>

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

                • 本文介绍了Swift,对于某些 UIViews 到他们的整体控制器单击时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have a DotBoss:UIViewController

                  There are a dozen UIView in the scene, Dot:UIView

                  (Some are direct subviews, some are further down.)

                  There are even container views in the chain between the highest controller and the Dot items.

                  The dozen Dot items know if they are tapped...

                  class Dot:UIView 
                      {
                      private var tap:UITapGestureRecognizer? = nil
                      override func awakeFromNib()
                          {
                          tap = UITapGestureRecognizer(target:self,
                                       action: #selector(SnapDot.handleTap(_:)))
                          self.addGestureRecognizer(tap!)
                          }
                      func handleTap(g:UITapGestureRecognizer)
                          {
                          print("user tapped on this particular Dot...")
                          }
                      }
                  

                  I want DotBoss to know when one of the Dot is tapped.

                  class DotBoss:UIViewController
                    {
                    func oneDotWasClicked(d:Dot)
                     {
                     }
                    }
                  

                  How to do this perfectly in Swift?


                  Note for anyone googling here, this bubbling extension is remarkably useful: https://blog.veloxdb.com/2016/05/12/bubbling-events-using-uiresponder-in-swift/

                  解决方案

                  A Dot (UIView) and its ultimately controlling DotBoss (UIViewController) are both responders, and are links along the responder chain. Therefore, a Dot can call a method in its DotBoss by walking the responder chain until it comes to the DotBoss:

                  func handleTap(g:UITapGestureRecognizer) {
                      // ... other stuff can go here if necessary ...
                      var r : UIResponder = self
                      repeat { r = r.nextResponder()! } while !(r is DotBoss)
                      (r as! DotBoss).oneDotWasClicked(self)
                  }
                  

                  这篇关于Swift,对于某些 UIViews 到他们的整体控制器单击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:打开和关闭其他 UIViewControllers - 除了使用协议 &amp; 之外的任何其他方法代表? 下一篇:Swift - 如何在 UITableViewCell 中使用 CollectionViewCell 打开另一个视图控制

                  相关文章

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

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

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