Reputation: 47364
I'm trying to have a single large UIView (for example a web view) which would have different transparent regions. Think of a cardboard cutout where a person can insert their head, like this:
The user should be able to tap on the screen where the user wants transparency to appear, to be able to dynamically edit content retrieved from the internet.
I want to know if it is possible to have a single UIView (for example an imageView or a web view) have regions of different transparency. For example a person's face may be made transparent and another face substituted in it's place.
Currently I know how to create a view like that using multiple UIViews with different transparencies. I also know how to set alpha for a single UIView.
Any input is appreciated.
Upvotes: 0
Views: 567
Reputation: 9902
Yes, this is possible. You can, for instance, use an image with Alpha channel in your view. If you want something like cardboard cutouts, you will probably create images for the cutouts anyway. Just have the head-holes transparent (and use transparent backgroundColor for the UIImageView).
There is nothing wrong with using a composite view to achieve the desired outcome, though. If you plan to reuse your view often, make it a UIView subclass.
Another way is using CALayer
's mask property.
Upvotes: 2