Zooming an image using UIScrollView
Ashish Sehra
13 posts
|
Hi, I have been trying to use the UIScrollView with a UIImageView as its subview so that i cud use the pinch and flick provided by UIScrollView for zooming and panning. but doest seem to work. I have tried by adding the following code. I was a bit unsure about how to make it a UIScrollViewDelegate so i just added <uiscrollviewdelegate> as a protocol in
Another thing. I found out in the iPhone documentation that we need to implement a couple of methods in a UIScrollViewDelegate. But i didnt understand how to do that. Do i just make empty methods or some logic is to be added there? Basically i didnt really understand the purpose of these two methods. The documentation had the following instructions. Can anyone please explain me what i m doing wrong? |
Ashish Sehra
13 posts
|
I think I found what the problem was. I just had to add a small fragment of code to indicate to the UIScrollView that wat view needs to be zoomed. I will post it in case someone is facing a similar problem.
|
demetrius ba...
18 posts
|
I’m having problems with this also. Do you have an idea on how to add this on the Scrolling sample code from the developer.apple.com website? Demetrius |
Ashish Sehra
13 posts
|
Hi Demetrius, I added the zooming in the scrolling part in the scrolling sample from apple. You can do this by following these steps:
|
demetrius ba...
18 posts
|
OK so I got it to work partially for scrollView1. MyViewController.h : @interface MyViewController : UIViewController <uiscrollviewdelegate> @property (nonatomic, retain) UIView *scrollView1; At MyViewController.m added :
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
return scroll2ImageView; It works but when you pinch, it pinches from all images. You get a mosaic of the images. I then changed error”i” undeclared (first use in this function) Something else that I tried was just adding to MyViewController.m: @synthesize scrollView1;
It works but only enlarges from the top left corner, and not from where you pinched. You can scroll from image to image though, and pinch every image. Any ideas to make it work properly would be helpful. Demetrius |
Ashish Sehra
13 posts
|
OK… there are a few things that cud be causing the problem.
That did the trick… Tested on the emulator… Seems to work for the last image… Still needs a little time to perfect it. I havent removed the for loop for adding other images which arent really helpful. Hope things work for u. Ashish. |
Ashish Sehra
13 posts
|
There is a really simple tutorial on Vimeo Good Luck. |
demetrius ba...
18 posts
|
The only thing that I can see is that this line of code would have to be changed from a single image: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”image0.jpg”]]; to multiple images. It’s using this code to pull in the images: NSString *imageName = [NSString stringWithFormat:@”image%d.jpg”, i]; UIImage *image = [UIImage imageNamed:imageName]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; Demetrius |
Ashish Sehra
13 posts
|
Hi Demetrius, I think u should post the contents of the Ashish |
demetrius ba...
18 posts
|
Here’s the clean code for
|
demetrius ba...
18 posts
|
Here’s the adjusted code:
|
demetrius ba...
18 posts
|
I think that the issue is: scroll1ImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”image0.jpg”]]; As it stands, it’s only viewing image0.jpg. Change it to @”image%d.jpg” and it pulls from all the images at once since the images are numbered 0-5. My idea is to somehow use this code, but I’m not sure how to go about it:
So I tried to use this code: scroll1ImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@”image%d.jpg”, i]]]; But I get a ‘error: “i” undeclared (first use of this function)’ Demetrius |
demetrius ba...
18 posts
|
So, I’ve managed to zoom in on each picture in the series. My only problem is that it zooms only from the left top corner down and doesn’t allow me to move the picture up and down. Demetrius |
13 posts, 2 voices
