gpt4 book ai didi

ios - UIScrollView 不使用 UItextfields 滚动

转载 作者:行者123 更新时间:2023-12-01 18:44:48 25 4
gpt4 key购买 nike

我正在制作一个普通 View ,用户可以在其中更新他们的个人资料。我按照这些步骤制作了该 View

  1. Created a new UIViewController with xib file
  2. Added a UIScrollView in super view
  3. Added almost 9 UITextField and 1 small UIWebView
  4. Satisfied Autolayout constraints like top UITextField will have top, left, right and height constrains and same for all the following controls but last UITextField 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com