IPhone: how to zoom only the image from scrollview?

I solved the problem, it's not the best code but works good for me for now, I will probably clean it a bit later. Posting here, maybe it will help someone :).

Up vote 0 down vote favorite share g+ share fb share tw.

I have this problem with ScrollView zoom. There are many articles about it but somehow I can't find proper explanation, tutorial or code snippet. I have full screen scrollview and inside a fullscreen imageview.

Inside imageview I load AspectFit images (they can be either vertical or horizontal, horizontal ones have black space above and under). When I make zoom I zoom not only the image but also the area around (the rest of imageview). Moreover, when I rotate simulator while in zoom the image goes to top-right corner instead of being centered like at start.

Few pixels even go out of the screen. I would really like to zoom only image instead of whole imageview or at least have the image centered all the time when zoomed. Any help welcome.. iphone xcode image uiscrollview link|improve this question asked Dec 6 '10 at 10:04yosh771623 93% accept rate.

I solved the problem, it's not the best code but works good for me for now, I will probably clean it a bit later. Posting here, maybe it will help someone :) UIImage *img = UIImage alloc initWithContentsOfFile:NSBundle mainBundle pathForResource:someImage ofType:@"jpg"; CGFloat scale; if (scrollView.frame.size. Width scrollView.frame.size.

Height) // landscape scale = scrollView.frame.size. Height / img.size. Height; imgView.

Frame = CGRectMake(scrollView.frame.origin. X, scrollView.frame.origin. Y, img.size.

Width*scale, img.size. Height*scale); imgView. Center = CGPointMake(scrollView.frame.size.

Width/2, scrollView.frame.size. Height/2); imgView setImage:img; scrollView setZoomScale:scale.

From the PhotoScroller example; add this to layoutSubviews: // center the image as it becomes smaller than the size of the screen CGSize boundsSize = self.bounds. Size; CGRect frameToCenter = imageView. Frame; // center horizontally if (frameToCenter.size.

Width Width - frameToCenter.size. Width) / 2; else frameToCenter.origin. X = 0; // center vertically if (frameToCenter.size.

Height Height - frameToCenter.size. Height) / 2; else frameToCenter.origin. Y = 0; imageView.

Frame = frameToCenter; This won't help with zooming only the image but it'll keep it centered when you zoom it at least.

I just change images with imgView. Image = UIImage imageNamed:whichNext; I don't really init any Rect with image. I just change the content of imageView.

– yosh Dec 6 '10 at 11:09 You'd put this in layoutSubviews - it's fine if you don't initialize the UIImageView's frame when you create it, it takes on the size of the image you initialize it with (though if you give it a different image with a new size you should call sizeToFit to resize it). As you can see in the above, you're not changing its size in this case either; you're just changing its origin so it'll center itself as you zoom out. – Ertebolle Dec 6 '10 at 11:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions