views:

46

answers:

1

How is an image that is larger than the iphone view size to a UIScrollView?

I tried to add the image to the UIImageView, still not connected to the UIScrollView and the image just shrunk to fit the UIImageView.

How is this structure set up?

Thanks

+1  A: 

You may want to do something like that :

- (void) resizeScrollContentView
{
    CGSize  viewSize = _imageView.frame.size;
    CGSize  scrollSize = _scroll.frame.size;
    CGPoint p;

    p.x = 0;
    p.y = 0;

    if(viewSize.width < 320)
    {
        p.x = 160 - (viewSize.width / 2.0);
    }

    if(viewSize.height < 460)
    {
        p.y = 200 - (viewSize.height / 2.0);
    }

    _imageView.frame = CGRectMake(p.x, p.y, _imageView.frame.size.width, _imageView.frame.size.height);

    CGSize endScrollSize;
    endScrollSize = _imageView.frame.size;

    _scroll.contentSize = endScrollSize;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
    [self resizeScrollContentView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _imageView;
}
TheSquad
Thanks, but what exactly does it do? Dont I have to do anything in IB?
alJaree
it bounds the imageView to the scrollingView, and resize it when you are zooming. If Zoom is greater than the phone size, it will let you scroll.No, you don't have to do anything on IB... Just create the ScrollView called here _scroll, and the UIImageView called here _imageView
TheSquad
I tried this and also set my imageview.image, but the view just shows as blank. Isnt it easier to do this in IB?
alJaree
I'm really not sure you can do this under IB... If you can, I don't know how. Sorry.
TheSquad