Search code examples
uiscrollviewuiimageviewxcode4.5

xcode 4.5 scroll on image wont work


I implemented a zoom on a picture which works just fine. It just wont scroll.

One thing to mention, I try to center the picture but that doesnt work either. Below is my code.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage * image = [UIImage imageNamed:@"family.jpeg"];
    self.imageview = [[UIImageView alloc] initWithImage:image];
    [self.view addSubview:self.imageview];

    [image drawInRect:CGRectMake((self.view.frame.size.width/2) - (image.size.width/2), (self.view.frame.size.height / 2) - (image.size.height / 2), image.size.width, image.size.height)];

    [self.scroller setContentSize:[image size]];
    [self.scroller setMaximumZoomScale:2.0];

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView
{
    return self.imageview;
}

Thanks very much for whatever help/comment you can provide:


Solution

  • For scrolling, the scrollview contentsize must be greater than the scrollview framesize. You just try this and see if it is scrolling.

    [self.scroller setContentSize:CGSizeMake(self.scroller.frame.size.width+500, self.scroller.frame.size.height+500)];

    If it is working, then your image size may be less than the frame size of your scrollview.