简体   繁体   English

如何将UIView的一部分显示在UIView的视图层次结构的后面并朝前

[英]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. 我的情节UIImageView板上有一个UIImageView ,它显示一个图像,该图像占据了整个屏幕的宽高比。 Then on top of that I have a large UIView that is centered on screen called middleView. 然后最重要的是,我有一个大的UIView ,它位于屏幕中间,称为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. 我想知道如何在屏幕上添加自定义UIViews ,以显示背面的UIImageView ,但仅显示它们覆盖的部分。 The effect I am wanting is for the custom UIViews to make it look like the large centered UIView middleView has holes in it. 我想要的效果是自定义UIViews ,使它看起来像大集中UIView middleView有孔。 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. 另外,我还需要前端自定义UIView是可变形的,以便它们内部的图像始终是背面imageView上当前位置的图像。

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. 最后要注意:背面UIImageView的图像将始终相同,因此我不一定需要知道背面UIImageView是什么。 The imageView will always be initialized with the same UIImage, start at the origin, and fill the screen with an aspect fill. imageView将始终使用相同的UIImage进行初始化,从原点开始,并用宽高比填充屏幕。

The effect I am wanting is for the custom UIViews to make it look like the large centered UIView middleView has holes in it 我想要的效果是使自定义UIView看起来像大的居中UIView middleView上有孔

It would be a lot simpler, surely, if the UIView middleView really did have holes in it. 如果UIView middleView确实确实有孔,那肯定会简单得多。 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: 例如,这张金星图像上有两个方孔,从背后的Stack Overflow广告中露出了一个愤怒的家伙:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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