在iOS中 - 在滚动视图中触摸文本字段时,视图无法滚动

时间:2012-08-26 00:49:18

标签: iphone xcode interface scrollview textfield

尝试通过触摸并拖动文本字段来滚动视图时,类似于在iPhone上的编辑联系人视图上滚动的方式,视图将不会移动,触摸和拖动文本字段之间或关闭在滚动视图中的文本字段的一侧工作,但在触摸文本字段时不工作。

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

4 个答案:

答案 0 :(得分:4)

尝试将已添加到文本字段的delaysContentTouches的{​​{1}}属性设置为YES。这应该允许您在触摸时滚动,然后在文本字段中拖动。

答案 1 :(得分:2)

this设置为=IF(A2<>A1,COUNTIF(A:A,A2),"") 对我来说也不起作用。什么做了迭代滚动浏览的手势识别器,并分别设置他们的delaysContentTouchestruedelaysTouchesBegancancelsTouchesInView

true

答案 2 :(得分:0)

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

extension UITableView {

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

}

答案 3 :(得分:0)

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

SWIFT 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)
  }
}