【问题标题】:Swift: Recognizing Scrolling Through UIViewSwift:通过 UIView 识别滚动
【发布时间】:2015-06-26 20:33:26
【问题描述】:

我有一个UIViewController,它创建自定义UIView 对象并将它们插入UIScrollViewUIViewControllerUIPanGestureRecognizer 附加到每个UIView。我可以做些什么来允许滚动UIScrollView,即使它通过自定义UIView 对象被触摸,同时仍然允许它们的UIPanGestureRecognizers(配置为仅更改x 坐标)工作?

这是我的意思的屏幕截图。蓝色矩形是自定义UIView 对象,白色背景是UIScrollView

任何帮助将不胜感激!

【问题讨论】:

  • 在做了更多研究之后,似乎使用UIGestureRecognizerDelegate (developer.apple.com/library/prerelease/ios/documentation/UIKit/…) 是这样做的方法。问题是,由于我是 Swift 新手,我不知道如何使用它。如果有人知道如何使用gestureRecognizer(_:shouldRecognizeSimultaneouslyWithGestureRecognizer:),我将不胜感激。

标签: ios swift uiview uiviewcontroller uiscrollview


【解决方案1】:

我想通了!

一切都是为了使用UIGestureRecognizerDelegate

在顶部,你做class ViewController: UIViewController, UIGestureRecognizerDelegate

然后,在类主体中,添加这个方法:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }

最后,在顶部的UIView 上添加panRecognizer.delegate = selfpanRecognizer 是引用UIViewUIGestureRecognizer 的变量

【讨论】:

  • 您能否添加更多代码细节。我没有得到 UIView 部分。我也是 swift 新手
  • 这是解决这个特定问题所需的所有代码。您需要帮助的是哪一部分?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
相关资源
最近更新 更多