iPhone - Draw transparent rectangle on UIView to reveal view beneath

后端 未结 4 2097
醉酒成梦
醉酒成梦 2020-11-28 21:13

I currently have two UIViews: one of a red background and the other blue. The blue view is a subview of the red view. What I would like to do is be able to \"cut\" out rec

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 21:43

    These may be the dumb ways but I would not do it the way you describe, but make it look the way you want it to look.

    (Jacques' answer just popped up - looks good to me)

    Approach 1: In the view controller to build a list of rectangles that tile around the exposed "hole". As your holes increase in number the number of tiling rects will also increase.

    Approach 2: Reverse your thinking. The blue view should be at the back with sections of the red view placed on top of it. You still see a red view with all but the "holes" masked by the blue view, but what you are really doing is copying regions from the view you want to expose and putting them on top of the mask as you make each hole. If you have some effect simulating depth you could add that as required with each hole.

    Neither requires subclassing or drawRect:.

提交回复
热议问题