4

当试图通过触摸和拖动文本字段来滚动视图时,类似于您在 iPhone 上的编辑联系人视图上滚动的方式,视图不会在文本字段之间移动、触摸和拖动或移到一边滚动视图中的文本字段有效,但在触摸文本字段时无效。

任何见解将不胜感激。谢谢!

4

4 回答 4

5

尝试将delaysContentTouches属性设置YESUIScrollView您已添加到文本字段的属性。如果您触摸然后在文本字段中拖动,这应该允许您滚动。

于 2012-08-26T02:21:13.440 回答
5

设置delaysContentTouchestrue对我也不起作用。所做的是遍历滚动视图的手势识别器并分别设置它们的delaysTouchesBegan和和:cancelsTouchesInViewtruefalse

scrollView.gestureRecognizers?.forEach {

    $0.delaysTouchesBegan = true; $0.cancelsTouchesInView = false
}
于 2018-05-08T04:19:23.917 回答
1

我认为它在这种情况下的解决方案

extension UITableView {

    override public func touchesShouldCancelInContentView(view: UIView) -> Bool {
        if view is UITextField || view is UITextView {
            return true
        }
        return super.touchesShouldCancelInContentView(view)
    }

}
于 2016-12-21T18:41:15.990 回答
0

尝试以下方法。只需将您的 UIScrollView 替换为 ScrollView 并将代码添加到您的项目中。

斯威夫特 4.1

class ScrollView: UIScrollView {
  override func touchesShouldCancel(in view: UIView) -> Bool {
    if type(of: view) == TextField.self || type(of: view) == UITextView.self {
      return true
    }
    return super.touchesShouldCancel(in: view)
  }
}
于 2018-06-21T17:45:52.803 回答