Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KardelSharpeye

macrumors member
Original poster
Apr 28, 2009
56
0
Hello,

does anyone know how to get the UIViewImage or the content inside of a UIScrollView after you add the image to the subview of the UIScrollView.

So if i have
UIViewImage *image;
UIScrollView *view;
[view addSubView:image]

anyone know how i can extract the image?
 
Well, you can do it three ways.

You can simply go [view.subviews objectAtIndex:0] (note that it won't always be 0 depending on the order you added the views to the scrollview).

You can make the image an instance variable (put it in the header file) and access it that way instead of calling it from the scrollview.

You can subclass scrollview, add the image there, then make the image an instance variable.
 
Well, you can do it three ways.

You can simply go [view.subviews objectAtIndex:0] (note that it won't always be 0 depending on the order you added the views to the scrollview).

You can make the image an instance variable (put it in the header file) and access it that way instead of calling it from the scrollview.

You can subclass scrollview, add the image there, then make the image an instance variable.

cool i am implementing your first method, however, i am not sure if it works yet so far there is no bug.

i am however having trouble with the pinching it doesnt seem to do anything to the image.

here is what i got:
UIImageView tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0 70.0, 70.0)];
tempImage.image = [[UIImage imageNamed:mad:"image.jpg"];
[tempImage setOpaque:YES];
[tempImage setUserInteractionEnabled:YES];

UIScrollView scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0 70.0, 70.0)];
scrollView.contentSize = CGSizeMake(70, 70);
scrollView.clipsToBounds = YES;
[scrollView setUserInteractionEnabled:YES];

[scrollView addSubview:tempImage];
[self addSubview:scrollView];

[tempImage release];
 
Hi! For zooming, you need to set more things.

You need to set the maximumZoomScale and minimumZoomScale (by default they're both 1.0, so it wouldn't zoom).

Then implement the viewForZoomingInScrollView method (part of the UIScrollViewDelegate) and return the imageView ([scrollView.subviews objectAtIndex:0] if you didn't set the imageView as an instance variable).

Lastly, you probably want to implement the scrollViewDidEndZooming in order to set the contentSize.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.