<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 到他们的整体控制器单击时

        Swift, for some UIViews to their overall controller when clicked(Swift,对于某些 UIViews 到他们的整体控制器单击时)
        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 到他们的整体控制器单击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  How to format localised strings in Swift?(如何在 Swift 中格式化本地化字符串?)
                  Why do we need to set delegate to self? Why isn#39;t it defaulted by the compiler?(为什么我们需要将委托设置为自我?为什么编译器不默认它?)
                  set delegate and datasource of uitableview programmatically in Swift(在 Swift 中以编程方式设置 uitableview 的委托和数据源)
                  How can I wait for a NSURLConnection delegate to finish before executing the next statement?(在执行下一条语句之前,如何等待 NSURLConnection 委托完成?)
                  Swift delegate beetween two VC without segue(两个没有 segue 的 VC 之间的 Swift 委托)
                    <tbody id='aGcTO'></tbody>

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

                          <legend id='aGcTO'><style id='aGcTO'><dir id='aGcTO'><q id='aGcTO'></q></dir></style></legend>
                          • <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'>