views:

173

answers:

2

Hi,

I am struggeling with my UIScrollview to get it to zoom-in the underlying UIImageView. In my view controller I set

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
 return myImageView;
}

In the viewDidLoad method I try to set the zoomScale to 2 as follows (note the UIImageView and Image is set in Interface Builder):

- (void)viewDidLoad {
 [super viewDidLoad];

 myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
 myScrollView.contentOffset = CGPointMake(941.0, 990.0);
 myScrollView.minimumZoomScale = 0.1;
 myScrollView.maximumZoomScale = 10.0;
 myScrollView.zoomScale = 0.7;
 myScrollView.clipsToBounds = YES;
 myScrollView.delegate = self;

 NSLog(@"zoomScale: %.1f, minZoolScale: %.3f", myScrollView.zoomScale, myScrollView.minimumZoomScale);
}

I tried a few variations of this, but the NSLog always shows a zoomScale of 1.0.

Any ideas where I screw this one up?

A: 

Here is another example I made. This one is using an image that is included in the resource folder. Compared to the one you have this one adds the UIImageView to the view as a subview and then changes the zoom to the whole view.

-(void)viewDidLoad{

[super viewDidLoad];

UIImage *image = [UIImage imageNamed:@"random.jpg"];

imageView = [[UIImageView alloc] initWithImage:image];

[self.view addSubview:imageView];

[(UIScrollView *) self.view setContentSize:[image size]];

[(UIScrollView *) self.view setMaximumZoomScale:2.0];

[(UIScrollView *) self.view setMinimumZoomScale:0.5];

}
flopex
Can't think why that could cause any trouble, but in my despair tried it anyway. Outcome unchanged
iFloh
+1  A: 

I finally got this to work. what caused the problem was the delegate call being at the end. I now moved it up and .... here we go.

New code looks like this:

- (void)viewDidLoad {
 [super viewDidLoad];

 myScrollView.delegate = self;
 myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
 myScrollView.contentOffset = CGPointMake(941.0, 990.0);
 myScrollView.minimumZoomScale = 0.1;
 myScrollView.maximumZoomScale = 10.0;
 myScrollView.zoomScale = 0.7;
 myScrollView.clipsToBounds = YES;
}
iFloh
Looks like this is caused by the OS calling -viewForZoomingInScrollView. If your delegate is nil, this call doesn't get made, so the view things zooming is disabled.
Ben Gottlieb