简体   繁体   中英

How to display part of a UIView at the back of a view hierarchy in a UIView towards the front

I have a UIImageView on my storyboard that displays an image that takes up the entire screen with aspect fill. Then on top of that I have a large UIView that is centered on screen called middleView. I am wondering how I can add custom UIViews on screen that will display the back UIImageView , but will only display the portion that they cover. The effect I am wanting is for the custom UIViews to make it look like the large centered UIView middleView has holes in it. Also I need for the front custom UIViews to be transformable so that the image inside them is always what is on the back imageView at their current position.

Final note: The image for the back UIImageView will always be the same so I don't necessarily need it to know what the back UIImageView is. The imageView will always be initialized with the same UIImage, start at the origin, and fill the screen with an aspect fill.

The effect I am wanting is for the custom UIViews to make it look like the large centered UIView middleView has holes in it

It would be a lot simpler, surely, if the UIView middleView really did have holes in it. This is easily achieved with a layer mask.

For example, this image of Venus has two square holes in it, revealing an angry-looking dude from a Stack Overflow ad behind it:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM