【问题标题】:iOS Swift: Propagates Swipe Events from nester controller to underneath controlleriOS Swift:将滑动事件从嵌套控制器传播到控制器下方
【发布时间】:2019-10-05 15:09:11
【问题描述】:

我有一个覆盖一半屏幕的嵌套 UIViewController。

在这个控制器下有父 ViewController。

我只想将横向滑动事件传播到底部(父)控制器。

我认为我应该使用以下函数

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    return (my test)
    })
  }

但我也知道这个函数应该应用于 UIView,而不是 UIViewController。所以我被卡住了,我不知道如何继续。

【问题讨论】:

    标签: ios swift uikit touches


    【解决方案1】:

    你可以创建

    class SomeView:UIView {
       override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
         return  true/false
       }
    }
    

    并将其分配给IB中孩子的vc'view,您也可以在vc内部实现这个

    override func touchesBegan(_ touches: Set<AnyHashable>, withEvent event: UIEvent) {
        var touch: UITouch? = touches.first
        //location is relative to the current view
        // do something with the touched point
        if touch?.view == childVC.view { 
        }
    }
    

    编辑:

    要将滑动操作传播给父级,添加一个委托并将滑动操作传递给子级,并在触发时通知父级与委托

    【讨论】:

    • 从 func point() 我怎么能理解这是一个水平平移手势?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    相关资源
    最近更新 更多