0

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.

user2280687
  • 203
  • 3
  • 9

1 Answers1

0

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:

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • As I demonstrate, for example, here: http://stackoverflow.com/a/23452614/341994 The hole I made is a square, but in fact it can be any shape you like. And of course you can have more than one hole. – matt May 20 '14 at 03:22
  • How would I add multiple masks. I need to have around 20 of these holes and when I use this method, only the last hole is punched in middleView. – user2280687 May 20 '14 at 03:38
  • Right - you only get one mask on a layer, but that mask can describe multiple holes. – matt May 20 '14 at 03:58
  • So how do I do this? When I try and add holes the inverse happens and instead of cutting out holes it determines what isn't cut out. – user2280687 May 20 '14 at 04:06
  • Did you look at the code I pointed you to? You really don't see how to add more holes to that code? – matt May 20 '14 at 04:15
  • Ok sorry - I was overcomplicating it - I figured it out. Thanks for your help. – user2280687 May 20 '14 at 04:19