【问题标题】:In iOS - When touching a text field in a scroll view the view can not scroll在 iOS 中 - 在滚动视图中触摸文本字段时,视图无法滚动
【发布时间】:2012-08-21 01:09:54
【问题描述】:

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

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

【问题讨论】:

    标签: iphone xcode interface scrollview textfield


    【解决方案1】:

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

    【讨论】:

    • 我正面临这个问题,这个答案对我没有帮助。 :(
    • 谢谢......我花了很多时间......在我尝试了你的答案并且它奏效之后...... :)
    【解决方案2】:

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

    scrollView.gestureRecognizers?.forEach {
    
        $0.delaysTouchesBegan = true; $0.cancelsTouchesInView = false
    }
    

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 迄今为止最好的解决方案,非常干净,并且您得到了您期望的确切行为。谢谢尼克。
      【解决方案4】:

      尝试以下方法。只需将您的 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)
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-02
        • 2012-06-22
        • 2012-06-29
        • 2012-11-03
        • 1970-01-01
        • 2014-02-16
        • 2013-11-07
        • 1970-01-01
        相关资源
        最近更新 更多