iPhone: Click view behind transparent UIScrollView

后端 未结 2 1637
清酒与你
清酒与你 2021-02-13 14:36

I have a UIScrollView that is set to have a clear background. Part of the scrollview does have content, but part does not (so it shows other views behind it). I would like to

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 15:24

    What we did was to subclass UIScrollView and implement logic that passes responsibility down to views under it, if the touch happens inside of the transparent area.

    In our case the transparent area is defined by contentOffset of 120 on Y axis, meaning our content starts 120 points below the start of the UIScrollView, and the code looks like this:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
        if (self.contentOffset.y < 0 && point.y < 0.0) {
            return NO;
        } else {
            return YES;
        }
    }
    

    Obviously this response is well past its prime but hopefully this is helpful to anyone searching for a solution.

提交回复
热议问题