Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone: uiscrollview doesn't scroll? but contentsize is set..?

hey people, I have some data and want to show this in a new view inside a navigation-stack.

I created some new viewcontroller class with XIB file. Then I edited the XIB file and placed the following hierachy:

1 files owner
2 first responder
3 scrollview
3.1 view
3.1.1 label1
3.1.2 label2
3.1.3 label3
3.1.4 image4

I arranged the labels and the image. the content of the labels may differ and they should size dynamically. I also did the IBOutlets in the viewcontroller class and connected everything correctly. the files owner's view delegate is set to view..

then I load the viewcontroller and I do in the "viewDidLoad" - method the following:

- (void)viewDidLoad {
[super viewDidLoad];

self.currentPageURL.text = [self.offerItem objectForKey: @"page-url"];
self.currentPrice.text = [self.offerItem objectForKey: @"price"];
self.currentRank.text = [self.offerItem objectForKey: @"rank"];
self.currentName.text = [self.offerItem objectForKey: @"name"];
self.currentProducerName.text = [self.offerItem objectForKey: @"producer-name"];

self.currentDescription.text = [self.offerItem objectForKey: @"description"];

self.imageViewForImage.image = [helperClass resizeImage:[self.offerItem objectForKey: @"picture"] forSize:CGSizeMake(280.0, 280.0) ];

[theScrollview setScrollEnabled:YES];
[theScrollview setContentSize:CGSizeMake(320, 1200)];
[theScrollview flashScrollIndicators];

[theScrollview addSubview:theView];

}

when I start the app in my simulator, everything is shown, but if I try to scroll, nothing happens..

what do I do wrong?

like image 234
dac Avatar asked May 22 '11 16:05

dac


People also ask

What is contentSize of ScrollView?

The content size of a scroll view doesn't change anything about the bounds of a scroll view and therefore does not impact how a scroll view composites its subviews. Instead, the content size defines the scrollable area. By default, a scroll view's content size is a big, fat {w:0, h:0} .

What is offset in iOS?

Offset this view by the specified horizontal and vertical distances. Assigns a name to the view's coordinate space, so other code can operate on dimensions like points and sizes relative to the named space.

What is contentOffset in ScrollView?

contentOffset ​Used to manually set the starting scroll offset. Type. Default. Point. {x: 0, y: 0}

How does ScrollView work iOS?

Overview. UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.


3 Answers

Autolayout set some constraints after the view loads, so, pick your code that sets the content size in viewDidLoad and put in viewDidAppear, and your code won't be rewritten.

This worked for me.

-(void)viewDidAppear:(BOOL)animated{
  [self.scrollView setContentSize:CGSizeMake(320, 1000)];
}

and sorry for my poor english.

like image 114
Thiago Pires Avatar answered Oct 18 '22 13:10

Thiago Pires


Ensure that "Use Autolayout" is unchecked in the IB Document attributes. I had the exact same issue, setting the correct contentSize and all, but with this feature enabled, scrolling was always disabled.

Use Autolayout needs to be OFF

UPDATE To use Autolayout, explicitly set the width and height of the scrollView's content in the viewDidAppear method, like this:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // set the scrollview to the specified size
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    [scrollView setContentSize:CGSizeMake(screenRect.size.width, 1100)];

    [scrollView setBounds:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];

    [scrollView setScrollIndicatorInsets:UIEdgeInsetsFromString(@"{0,0,0,-1.0}")];

}
like image 36
John Paul Barbagallo Avatar answered Oct 18 '22 13:10

John Paul Barbagallo


Immediately change the frame of theScrollView to 320x480 and you should see scrolling.

like image 4
Deepak Danduprolu Avatar answered Oct 18 '22 13:10

Deepak Danduprolu