V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
kuoruan
V2EX  ›  iDev

如何将父 View 的滑动事件传递给它的子 View?

  •  
  •   kuoruan · Jul 27, 2017 · 5061 views
    This topic created in 3200 days ago, the information mentioned may be changed or developed.
    一个 UIView 里边有个 UIScrollView,scrollview 小于父 View,现在想要在父 View 的空白区域上下滑动的时候能将滑动传递给 scrollview,以使 scrollview 滚动。
    滑动事件不在 scrollview 上,这种情况应该如何处理?
    8 replies    2017-07-29 10:45:49 +08:00
    f19009
        1
    f19009  
       Jul 27, 2017
    可以修改 hitTest
    yautou
        2
    yautou  
       Jul 27, 2017 via iPhone
    简单点,滑动的时候设置 scrollview 的 offset 就行了呀
    cubesugar
        3
    cubesugar  
       Jul 28, 2017
    给 scrollview 的 content 设置 margin,不知是不是一种满足要求的方案,margin 的大小就是 空白区域的大小。app 里一些 profile 页面有这样处理过
    kuoruan
        4
    kuoruan  
    OP
       Jul 28, 2017
    @yautou 估计也就只能这样处理了,感谢
    SnailLin
        5
    SnailLin  
       Jul 28, 2017
    加个手势
    或者重写 func point(inside point: CGPoint, with event: UIEvent?) -> Bool 扩大响应面积
    方法应该还是很多的
    kuoruan
        6
    kuoruan  
    OP
       Jul 28, 2017
    @f19009 刚才看了一下 hitTest,貌似可以实现,是不是需要将 UIView 上的 ponit 转化到 scrollview 上?然后调用 scrollview 的 hitTest?
    Sapp
        7
    Sapp  
       Jul 28, 2017
    最简单的就是 父元素触发事件的时候获取 offsetTop 同时设置为子元素的 offsetTop。
    zichen0422
        8
    zichen0422  
       Jul 29, 2017
    1, 手势处理, UIView 方向滑动. 识别即可
    2, touch begin / touch end 识别滑动也可
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2474 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 08:01 · PVG 16:01 · LAX 01:01 · JFK 04:01
    ♥ Do have faith in what you're doing.