• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

拖动按钮时ScrollView不滚动

用户头像
it1352
帮助7

问题说明

我有一个滚动视图,当它上面没有按钮时会滚动.现在确实如此,并且当拖动鼠标(在模拟器上)时,什么也没有发生(我认为是因为按钮被按下了).我怎样才能做到这一点?

I have a scroll view that used to scroll when it didn't have buttons all over it. Now it does, and when dragging the mouse (on simulator) nothing happens (i think because the buttons are being pushed). How can I make this right?

正确答案

#1

发生这种情况是因为 UIScrollViewUIButton 子视图(我假设按钮作为子视图添加到您的case) 正在跟踪触摸而不是滚动视图.UIScrollView 方法 touchesShouldCancelInContentView 是这里的关键.根据其描述:如果view不是UIControl对象,则默认返回YES;否则返回NO.",即对于UIControl 对象(按钮),UIScrollView 不会尝试取消阻止滚动的触摸.

This is happening because UIButton subviews of the UIScrollView (I assume buttons are added as subviews in your case) are tracking the touches and not the scroll view. UIScrollView method touchesShouldCancelInContentView is the key here. According to its description: "The default returned value is YES if view is not a UIControl object; otherwise, it returns NO.", i.e. for UIControl objects (buttons), UIScrollView does not attempt to cancel touches which prevents scrolling.

所以,要允许使用按钮滚动:

So, to allow scrolling with buttons:

  1. 确保 UIScrollView 属性 canCancelContentTouches 设置为 YES.
  2. 子类 UIScrollView 并覆盖 touchesShouldCancelInContentView 以在内容视图对象是 UIButton 时返回 YES,如下所示:
  1. Make sure UIScrollView property canCancelContentTouches is set to YES.
  2. Subclass UIScrollView and override touchesShouldCancelInContentView to return YES when content view object is a UIButton, like this:
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
    if ( [view isKindOfClass:[UIButton class]] ) {
        return YES;
    }

    return [super touchesShouldCancelInContentView:view];
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangicajg
系列文章
更多 icon
同类精品
更多 icon
继续加载