【发布时间】:2012-08-21 01:09:54
【问题描述】:
当尝试通过触摸和拖动文本字段来滚动视图时,类似于您在 iPhone 上的编辑联系人视图上滚动时,视图不会在文本字段之间移动、触摸和拖动或关闭滚动视图中文本字段的一侧有效,但在触摸文本字段时无效。
任何见解将不胜感激。谢谢!
【问题讨论】:
标签: iphone xcode interface scrollview textfield
当尝试通过触摸和拖动文本字段来滚动视图时,类似于您在 iPhone 上的编辑联系人视图上滚动时,视图不会在文本字段之间移动、触摸和拖动或关闭滚动视图中文本字段的一侧有效,但在触摸文本字段时无效。
任何见解将不胜感激。谢谢!
【问题讨论】:
标签: iphone xcode interface scrollview textfield
尝试将delaysContentTouches 属性设置为YES,以便将UIScrollView 添加到文本字段中。如果您在文本字段中触摸然后拖动,这应该允许您滚动。
【讨论】:
将delaysContentTouches 设置为true 也对我不起作用。所做的是遍历滚动视图的手势识别器并将它们的 delaysTouchesBegan 和 cancelsTouchesInView 分别设置为 true 和 false:
scrollView.gestureRecognizers?.forEach {
$0.delaysTouchesBegan = true; $0.cancelsTouchesInView = false
}
【讨论】:
我认为它在这种情况下的解决方案
extension UITableView {
override public func touchesShouldCancelInContentView(view: UIView) -> Bool {
if view is UITextField || view is UITextView {
return true
}
return super.touchesShouldCancelInContentView(view)
}
}
【讨论】:
尝试以下方法。只需将您的 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)
}
}
【讨论】: