Draw a shadow which is hidden under the semi-transparent view?

廉价感情. 提交于 2019-12-21 21:43:06

问题


I have a semi-transparent view with a drop shadow. I mocked it up in photoshop, which doesn't draw the shadow under the object. Then I made it in xcode, but it obviously does draw the shadow underneath. I was wondering if there's a way to avoid this. In other words - have the shadow only appear outside of the shape?


回答1:


You probably want to set the rasterized property of the layer to YES, which will composite the shadow before other effects such as opacity are applied to the view.

Note however that this has a big performance impact. There's a handy table of different shadow implementations and their performance implications here: http://www.omnigroup.com/blog/entry/ipad_drop_shadow_performance_test/




回答2:


Use CGContextEOClip to set up a clipping path that excludes your shape, then set up your shadow and draw the shape with full opacity. There is some example code in this answer.



来源:https://stackoverflow.com/questions/8552073/draw-a-shadow-which-is-hidden-under-the-semi-transparent-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!