【问题标题】:UIScrollView behaviorUIScrollView 行为
【发布时间】:2015-03-26 18:17:58
【问题描述】:

我有一个这样配置的 UIScrollView:

canCancelContentTouches:YES    
delaysContentTouches:NO

在 UIScrollView 内部,我有一些 UIButton(想想缩略图)。如果我单击一个按钮,则会检测到触摸,然后如果我开始滚动,则会按预期取消 UIButton 上的触摸。

我遇到的问题是,如果我给 UIScrollView 一个很好的摆动,并且我通过简单地触摸 UIScrollView 来停止滚动,一旦我触摸 UIButton,它会在按住按钮大约 1 秒后收到 touchesCancelled,直到我重新滚动 UIScrollView

问题似乎来自 UIScrollView 仍然认为它正在被拖动(这是错误的,因为我最后一次触摸时还没有移动)。

奇怪的是,如果我通过[UIScrollView setBounces:false] 禁用弹跳,问题就不再存在了。但是我显然失去了反弹,这是有问题的。

我尝试了很多方法,比如禁用/重新启用滚动视图,它的手势识别器。我在这里没有想法了。

【问题讨论】:

    标签: ios objective-c iphone uiscrollview uibutton


    【解决方案1】:

    当 uibutton 收到触摸开始时,您可以在此处执行操作,您可以将 uiscrollview contentsize 设置为等于 uiscrollview superview 大小。

    当 uibutton 接收到 touch end 时,您可以将 uiscrollview contentsize 设置回原来的样子。

    通过将 uiscrollview contentsize 设置为 uiscrollview superview 大小,它将不允许 uiscrollview 内容移动。

    【讨论】:

    • 感谢您的输入,但用户应该可以随时滚动。我需要一种方法来告诉 UIScrollView 在我完成触摸它之后,它不会再认为它仍然在我的下一次触摸时被拖动
    • 当您将 uiscrollview contentsize 设置回原来的值时,当 uibutton 接收到触摸结束时,UIScrollview 将是可滚动的。你必须继承你的 UIButton 并添加 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 在这里你设置滚动视图内容大小等于超级视图大小和 - (void)touchesEnded:(NSSet *)touches withEvent: (UIEvent *)event 在这里你将scrollview contentsize设置回原来的样子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多