1
votes

I've a UIScrollView - 590 x 650 I've 2 UIImages in the scroll view with dimensions : 620 x 450 So, I set the contentsize and properties thus :

    self.scroller.minimumZoomScale=0.5;
    self.scroller.maximumZoomScale=6.0;
    self.scroller.contentSize=CGSizeMake(1350, 950);// EDIT : 1350 because 620 + 620 
    //950 because 450 + 450 and 50 extra

    self.scroller.contentInset=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);
    self.scroller.scrollIndicatorInsets=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);

    self.scroller.delegate=self;

But when I try to run and scroll, only half/partial of the second image is displayed and the scroll bounces back, even when I pull the scroll all the way to display the end of the second image.

what am i doing wrong here??
Is my content size setting/assumption correct??

If this question is already answered please point me to it, as I couldn't find the correct explanation.

EDITS : *.h file

@interface ViewController : UIViewController<UIScrollViewDelegate>
{
    UIScrollView *scroller;
    UIImageView *varImage1;
    UILabel *lblStyle;
    BOOL isAlpha;
    UITextView *textView;
}

@property (retain, nonatomic) IBOutlet UIScrollView *scroller;
@property (retain, nonatomic) IBOutlet UIImageView *varImage1;
@property (retain, nonatomic) IBOutlet UILabel *lblStyle;

- (IBAction)notesClick:(id)sender;
@property (retain, nonatomic) IBOutlet UIButton *notesClick;

@property (retain, nonatomic) IBOutlet UITextView *textView;


@end

*.m file

// calculate minimum scale to perfectly fit image width, and begin at that scale
    float minimumScale = [scroller frame].size.width  / [varImage1 frame].size.width;
    [scroller setMinimumZoomScale:minimumScale];
    [scroller setZoomScale:minimumScale];
    scroller.contentSize= CGSizeMake(960,1170);

    scroller.delegate=self;

Image size is 1170x960 UIImage view size is : 1170x960 (width x height) picture set form IB and property set to scale to fit.

scroll view size is 590 x 650 (width x height)

object hierarchy :

enter image description here

Initial view on load : *NOTE : Even thought image is partially displayed, I can't scroll to the right and see the rest of the image. enter image description here

After i zoom out the image, I can scroll even if the image is only partially being displayed enter image description here

1
your images width is 620 so 620+620= 1240 not 1200 So please set content size self.scroller.contentSize=CGSizeMake(1350, 950);kb920
What you're saying is correct. But that doesn't help anyway in answering the query. The UIImage still bounces back when I scroll vertically and doesn't show the second image completely.anotherCoder
@Vinu, Have you checked the frame for UIScrollView? Is it outside it's superview by any chance?iDev
@ACB : Yes I have checked it. The placement of the left top corner of the UIScrollView is at 0,0. So no problem there.anotherCoder

1 Answers

0
votes

Would you show us the code, where you create and add the images?

Also a safe and general way would be the following:

CGSize contentSize = CGSizeZero;
for(UIView *view in self.scroller.subviews) {
  contentSize.height = MAX(contentSize.height, view.frame.origin.y + view.frame.size.height);
  contentSize.width  = MAX(contentSize.width, view.frame.origin.x + view.frame.size.width);
}
CGFloat border = 50;
contentSize.height += border;
contentSize.width  += border;
self.scroller.contentSize = contentSize;

It will just find the lowest and most right position of any view in the scrollView and use it as the contentSize.