views:

53

answers:

2

In my view I have a picture.. The picture has a 3:2 scale and is huge, resolution wise.

I'm having a lot of trouble initializing a UIImage with the image to the original size and then zooming out of the UIImageView so that the entire image is visible within the scrollview.

The program stays only in the portrait orientation.

And no, please don't say to just use UIWebView. UIWebView doesn't let me set the content size during view load...instead, it just zooms out of the image by some arbitrary scale and I couldn't figure out a way to adjust the scale value (I don't think it's possible).

Thanks for any responses! I really appreciate them :D

+1  A: 

You almost certainly don't want to load your 'huge, resolution wise' image all at once on load regardless of it's scale. I'd suggest checking out some of Apple's sample code on this stuff (starting with ScrollViewSuite would be good, I'd say).

There was also a recent video released from WWDC where they implement this sort of thing live (they have more of a photo viewing app, but you could pretty easily do what they show with just one image too) so take a look for that too.

thenduks
+1  A: 

Here's an example of placing an image that responds to pinch-to-zoom. Basically, you place the UIImageView in a UIScrollView and change some settings.

UIImageView *myImage;
UIScrollView *myScroll;

-(void)viewDidLoad{

  myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,360,450)];
  [myImage setImage:[UIImage imageNamed:@"coolpic.png"]];
  myImage.contentMode = UIViewContentModeScaleAspectFit;
  [myScroll addSubview:myImage];
  [myScroll setContentSize:CGSizeMake(myImage.frame.size.width, myImage.frame.size.height)];
  [myScroll setMinimumZoomScale:1.0];
  [myScroll setMaximumZoomScale:4.0];
}

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

Of course, set all your delegates and IB hooks properly.

Edit: I just reread your question. The portion of the example that answers your question is the frame specification of the UIImageView and its contentMode setting.

B_