我正在制作一个普通 View ,用户可以在其中更新他们的个人资料。我按照这些步骤制作了该 View
- Created a new
UIViewController
with xib file- Added a
UIScrollView
in super view- Added almost 9
UITextField
and 1 smallUIWebView
- Satisfied Autolayout constraints like top
UITextField
will have top, left, right and height constrains and same for all the following controls but lastUITextField
have top, left, right, bottom and height constraints.
现在所有约束都已应用并得到满足,但是当我运行 View 然后尝试通过拖动
UITextField
进行滚动时然后 ScrollView 不滚动,但如果我通过从 UITextField
以外的某个区域拖动来滚动然后它滚动得很好。谁能告诉我主要问题是什么?Note: there is no code yet other than setting up xib file. A sample project is available on this link https://www.dropbox.com/s/7oqry8yzd9twnp1/TestScroll.zip?dl=0
最佳答案
覆盖 UIScrollView touchesShouldCancelInContentView
方法将解决这个问题。
According to Apple touchesShouldCancelInContentView is called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur.
默认情况下,如果 View 是
UIControl
,则此方法返回 NO。 .所以 UIControls 不会发生滚动。如果我们从这个方法返回 YES,触摸将不会被传递到 subview ,因此会发生滚动。
所以覆盖 UIScrollView
touchesShouldCancelInContentView
喜欢以下@interface MyScrollView : UIScrollView
@end
@implementation MyScrollView
- (BOOL)touchesShouldCancelInContentView:(UIView *)view{
return YES;
}
@end
注意:
touchesShouldCancelInContentView
方法仅在我们设置 canCancelContentTouches
时调用属性为 YES希望这可以帮助。
关于ios - UIScrollView 不使用 UItextfields 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37156293/