How do I create a copy of an UIImageView instance that can be manipulated independently of the first instance?
I've tried UIImageView *tempCopy = [instance copy]
but it crashes. Is there another way?
It probably crashes because UIImageView doesn't conform to the NSCopying protocol. So do it yourself: instantiate a new UIImageView and set any property from your original that you find of interest.
UIImageView
doesn't conform to NSCopying
, but it does conform to NSCoding
. Archive your view, and then de-archive it to get a brand new copy.
For the lazily inclined, this looks like:
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:imageView];
UIImageView *copy = [NSKeyedUnarchiver unarchiveObjectWithData:data];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With