2

So I want to duplicate a UIView - and by duplication I mean duplicate everything, including its bounds, frame, size, coordinates, sense of what is its superview etc. This UIView has an image inside of it - I need to retain that image too.

Can anyone please tell me a straightforward way to do this? I looked at this - UIView duplicate but that doesn't seem to work with UIImage, plus is giving me an error saying "unrecognized selector sent to...".

Basically, I am picking a UIView out of a grid of UIViews, and when I pick the UIView out (containing an image), I need to create a copy of the UIView which will replace it. If you have any other suggestions on how to go about doing this, they are more than welcome too.

Community
  • 1
  • 1
Ak1
  • 661
  • 1
  • 6
  • 6
  • 2
    This sounds a lot like your view layer and model layers aren't, well, layered. There should be no "picking up" of a UIView out of a grid of UIViews. If an item is selected, the controller layer should take care of setting up the new view and then connecting it to whatever model layer bit is encapsulating that state. What you are asking is hard to do exactly because it is not considered an architecturally sound approach. – bbum Jun 13 '11 at 22:55
  • Did you ever find out how to do this? I wanted to do this for a game animation. I don't want to have to manually (in code) copy over all the properties and subviews etc.. – Sam Jarman Jul 19 '11 at 06:11

1 Answers1

0

How did you initially create the view that you want to copy? Can you do that again?

Something about the view is going to need to change at some point -- bounds, content, etc. Otherwise, you'll have two identical views in the same location, and that's probably not helpful.

All the information that determines how the view should look should be stored in a data model, not in the view, so it shouldn't be a big deal to create another view that displays that same information.

Caleb
  • 124,013
  • 19
  • 183
  • 272