views:

66

answers:

1

Hi,

i have a scroll view which represents a map, it has pins on it, when the user zooms the map, my app uses viewForZoomingInScrollView to ensure all the pins remain the same size( I ensure the location of the pin point is maintained by setting the anchor point on the layer) here is the general gist of the code..

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    NSLog(@"view for zooming in scroll view...");

    double scale = mapScrollViewSize.width/scaledSize.width;
    NSArray *pins = [mapView subviews];
    for (int i=0; i<[mapPins count]; i++) 
    {
        AMapPin *mapPin = (AMapPin *)[mapPins objectAtIndex:i];
        if([mapPin isKindOfClass:[AMapPin class]])
        {
            CGAffineTransform transform1 = CGAffineTransformMakeScale(scale, scale);
            mapPin.transform = transform1;
        }
    }
    return mapView;
} 

this works fine on OS versions right up to 3.1.3 when i scroll i can see the NSLog in the console repeatedly and my subviews resize themselves correctly (DURING zooming) .. in iOS4 and indeed in the emulator for SDK 4 and on the iPhone 4, the selector only seems to be called once, rather than repeatedly on earlier OS versions, so the resizing of the sub views has no effect at all.

I assume the design has changed but i want to know what my best option is for either a) changing my code so it works using viewForZoomingInScrollView keeping changes to a bare minimum b) how to make use of the new 3.2 selector called scrollViewDidZoom which does work BUT maintaining support for earlier OS versions AND with the minimum amount of extra code, im no expert on cross version compatibility and how to most efficiently achieve it

Thanks

+1  A: 

Would this be compatible?

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    [self scrollViewDidZoom:scrollView];
    return mapView;
} 

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    NSLog(@"view for zooming in scroll view...");

    double scale = mapScrollViewSize.width/scaledSize.width;
    NSArray *pins = [mapView subviews];
    for (int i=0; i<[mapPins count]; i++) 
    {
        AMapPin *mapPin = (AMapPin *)[mapPins objectAtIndex:i];
        if([mapPin isKindOfClass:[AMapPin class]])
        {
            CGAffineTransform transform1 = CGAffineTransformMakeScale(scale, scale);
            mapPin.transform = transform1;
        }
    }
}
v01d
thanks, i did do this but was not sure it was the "best" way to do it, the documentation is pretty weak on the new scrollViewDidZoom so as this works (tested on devices and emulators) ill stick with it until someone says otherwise, cheers!
Matt