I have a UIView in a scrollview that contains about 100 subviews. The subviews all look the same and are instances of the same class. I have a transform that I want to apply to each subview. But the transform needs to change everytime zoomScale changes.
What’s the best way to apply the transform to all the views? Currently Im implementing layoutSubviews, getting the array of subviews, and setting each subview’s transform to the new transform.
Is there an optimal way to do this?
Update:
The views I want to transform are pins on a map. When I zoom in with scrollView they need to be scaled down (i.e. so they look the same size to the user) and remain locked to the same position).
- (void)layoutSubviews
{
CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue);
for(UIView *view in self.subviews){
view.transform = transform;
}
}
…
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
self.mapMarkerContainer.zoomValue = scrollView.zoomScale;
[self.mapMarkerContainer setNeedsLayout];
}
After a bit of research around this, it turns out that my initial method is the most efficient:
Sometimes I guess you just have to accept that there are limitations on how quick an iPhone can process data.