How to make a portion of an UIImageView transparent in order to show views in layers below

纵饮孤独 提交于 2019-12-11 08:26:37

问题


Here is a photo explanation to better illustrate what I mean:

I have two UIImageViews, with View1 being on the bottom and View2 at the top:

What I would like to do accomplish is to programmatically set an area on View2 that is completely transparent (i.e. has an alpha of 0), so that this will be the end result:

I haven't been able to find a similar problem related to marking a part of a UIImageView transparent in the form of a shape (specifically, a circle), and was wondering how I should tackle this problem?

Thanks!


回答1:


One road you could go is CoreGraphics:

  1. Create an image context
  2. Set the clipping path you need (or just clear the circle for the "hole" after drawing)
  3. Draw the original image into the context
  4. Make an UIImage from that context
  5. Assign the image to the top UIImageView

https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/HandlingImages/Images.html#//apple_ref/doc/uid/TP40010156-CH13-SW1



来源:https://stackoverflow.com/questions/23587596/how-to-make-a-portion-of-an-uiimageview-transparent-in-order-to-show-views-in-la

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