I want to display a photo in a scroll view. Because I want to display the whole photo to the user and then allow user to pinch the photo to zoom in and out. So firstly I set the contentsize to a fixed size(such as (320, 568)). However, when I add a UIImageView as the subview of the the scroll view, if the image of the UIImageView's size is larger than the contentsize of the scroll view, only the upper and left part of the image will be displayed. So I want to know how to restrict the imageview in the scrollview and set image displayed well(like the photo in most apps). I know a method: clipsToBounds, and I use it. But it dose not work. Can anyone help me? Here is my simple code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.photoScrollView.contentSize = CGSizeMake(320, 568);
self.photoScrollView.clipsToBounds = YES;
UIImage *image = [UIImage imageNamed:@"image"];
UIImageView *iv = [[UIImageView alloc] initWithImage:image];
[self.photoScrollView addSubview:iv];
[iv sizeToFit];
iv.contentMode = UIViewContentModeScaleAspectFit;
}
Thanks in advance!