Zooming delegate code in chapter 6 (p. 123)


#1

Your code, HypnosisView, obviously works.

I then modified it to have the UIViewController serve as the , not the AppDelegate.

My modified version does not work because the delegate method -viewForZoomingInScrollView is not called.

For my modified version, I have your code on your page 123 inside my UIViewController’s -viewDidLoad method in the form:

    // - (void )setUpPinchToZoom:(CGRect)thisRect withinThisView:(UIView *)thisView;
    [self setUpPinchToZoom:thisRect withinThisView];

Also, in my UIViewController.m I have:

- (void )setUpPinchToZoom:(CGRect)thisRect withinThisView:(UIView *)thisView
{
    UIScrollView *localScrollView = [[UIScrollView alloc] initWithFrame];
    [thisView addSubview:localScrollView];
    
    CGRect bigRect;
    bigRect.origin = CGPointZero;
    bigRect.size.width  = thisRect.size.width  * 2;
    bigRect.size.height = thisRect.size.height * 2;
    [localScrollView setContentSize:bigRect.size];
    
    CGPoint offset;
    offset.x = thisRect.size.width  * 0.5;
    offset.y = thisRect.size.height * 0.5;
    [localScrollView setContentOffset:offset];

    [localScrollView setMinimumZoomScale:1.0];
    [localScrollView setMaximumZoomScale:3.0];
    [localScrollView setDelegate:self];
    
    UIView *localZoomView = [[UIView alloc] initWithFrame:itsWholeViewScroller.frame];
    [localZoomView setBackgroundColor:[UIColor clearColor]];
    [localScrollView addSubview:localZoomView];

    self.itsZoomView = localZoomView;   // UIView *itsZoomView in my UIViewController's .h

    [localZoomView release];
    
    [localScrollView release];
}

together with the delegate method which is never called ???

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{    
    return self.itsZoomView;
}

I know … I know … the above code listing is long … but it is just an adaptation of code in Chapter 6 … so I hope you’ll forgive me.

John Love