2

I have a UIView, and I want to make multiple replicas of it that I can position on different points of the screen. I also want to be able to apply different masks/transforms to each of the replicas so that each one can potentially show a different portion of the original.

For example, let's say that that I have a view, A, and I make two replicas of it, B, and C. I want to then apply a mask to B so that it only shows the top half of A and I want to apply a different mask to C so that it only shows the bottom half of A.

How would I go about doing this?

CAReplicatorLayer isn't really usable for what I'm trying to do in my application as the replicas need to be in different parts of the view hierarchy. Also, I can't use any method that makes use of snapshotting as the original view may contain animated content or video. What I really want is some sort of view that can mirror the contents of another view so that I have two views that look exactly the same.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Antonio
  • 988
  • 1
  • 7
  • 12
  • Create a subclass of UIView with whatever subviews you need, and instantiate multiple instances of it. – rdelmar Mar 21 '15 at 04:50
  • 1
    @rdelmar That's not really an option for what I'm doing as that could be extremely expensive, especially for large complicated view hierarchies. Also, the view hierarchy could have video playing within it, and so all of the video players would have to stay in sync at the same time, which would not be easy. Instead of using up tons of extra memory, I'm trying to look for a way of drawing a single view hierarchy in multiple places. – Antonio Mar 21 '15 at 05:07
  • How is that different? If you draw the same content in different places, then you're essentially recreating the views. If you can't use an image of the view, then your only other choice is another instance of that view. I don't think there is any other way. As far as the videos having to stay in sync, I don't know why you would have to do that (unless that's what you want). – rdelmar Mar 21 '15 at 05:25
  • Hypothetically, let's say that we have a view hierarchy with 1 million views in it. Making a copy of it would require copying 1 million different things, which is too expensive for what I want to do. But ultimately, that gigantic view hierarchy will get drawn into a buffer somewhere and it would be nice if I could get the contents of that buffer to display in multiple locations on the screen. Basically, I want a view that can use the rendered output of another view instead of generating its own. – Antonio Mar 21 '15 at 05:40
  • 1
    CAReplicatorLayer does what I want, but it's not flexible enough for what I'm trying to do. So I'm wondering if it's possible to recreate what CAReplicatorLayer does from scratch in a way that I have more control over. – Antonio Mar 21 '15 at 05:43
  • How about using a FBO (a frame buffer object). The idea is you draw the whole scene once on the FBO which has a bound texture. Then you can draw the texture at any position, any view, multiple times and use any filters you want. Well, any filter that is not geometry related which seems to be your case. – Matic Oblak Mar 23 '15 at 13:18
  • Thanks Matic! I don't know very much about Open GL, but I'll look into doing what you said. Do you think this method would play well with UIKit? How would I get a specific UIView to display the texture? Also, do you know of any example code that you could point me to? – Antonio Mar 23 '15 at 18:00

0 Answers0