Im have a subclass of UIView, called PinView, which contains an image. Basically PinView gets added multiple times to my app, and then I perform a transform on PinView objects. The issue is that when I add a lot of PinViews, my app gets sluggish because I am transforming each PinView.
Ideally, I want to have one 'static' PinView that gets added to a UIView multiple times but i only have to transform it once. Currently this doesn't seem to work. Every time I add the static PinView to my UIView, it will only ever appear in the UIView once (due to it only being able to have one superview I'm guessing).
Im struggle to find out the best way to go about solving this problem - how do I use a single pointer to a PinView, add it multiple times to a UIView and be able to perform a transform on the PinView which gets passed on to PinViews displayed in my UIView? (by the way, the transform is always the same for all the PinViews).
Im assuming this will be the best way to get a performance improvement, if this is not the case please let me know.
UPDATE:
- (void)layoutSubviews { CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue); NSMutableArray *mut = nil; PinView *pinView = nil; CallOutView *callOut = nil; //get all dictionary entries for(NSString *identifier in self.annotationsDict.allKeys){ //get the array from dictionary mut = [(NSArray *)([self.annotationsDict objectForKey:identifier]) mutableCopy]; //change layout if not nil if([[mut objectAtIndex:PIN] isKindOfClass:[PinView class]]){ pinView = ((PinView *)[mut objectAtIndex:PIN]); pinView.transform = transform; [mut replaceObjectAtIndex:PIN withObject:pinView]; } if([[mut objectAtIndex:CALL_OUT] isKindOfClass:[CallOutView class]]){ callOut = ((CallOutView *)[mut objectAtIndex:CALL_OUT]); callOut.transform = transform; [mut replaceObjectAtIndex:CALL_OUT withObject:callOut]; if(pinView !=nil)callOut.center = CGPointMake(pinView.center.x, pinView.center.y - pinView.frame.size.height); } [self updateAnnotationsKey:identifier forObject:[NSArray arrayWithArray:mut]]; mut = nil; pinView = nil; callOut = nil; } } UPDATE:
Removed the above and now just have:
- (void)layoutSubviews { CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue); for(UIView *view in self.subviews){ view.transform = transform; } }