Iphone: uiscrollview not scrolling? but contentize is installed ..?

Hey people, I have some data and you want to show it in a new view inside the navigation stack.

I created a new viewcontroller class with an XIB file. Then I edited the XIB file and placed the following hierarchy:

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 laid out the tags and the image. Label content may vary and should be dynamically distributed. I also made IBOutlets in the viewcontroller class and connected everything correctly. The file owner view delegate is set to view.

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

 - (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 run the application in my simulator everything is displayed, but if I try to scroll, nothing happens.

what am I doing wrong?

+6
source share
3 answers

Immediately change the frame of theScrollView to 320x480 and you will see a scroll.

+4
source

Autolayout sets some restrictions after loading the view, so select your code that sets the size of the content in viewDidLoad and puts it in viewDidAppear, and your code will not be overwritten.

It worked for me.

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

and sorry for my poor english.

+17
source

Make sure the Use Self-timer option is not checked in the attributes of the IB document. I had the same problem setting the correct contentSize and all, but with the function turned on, scrolling was always disabled.

Use Autolayout needs to be OFF

UPDATE To use Autolayout, explicitly set the width and height of the scrollView content in the viewDidAppear method, for example:

 - (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}")]; } 
+8
source

Source: https://habr.com/ru/post/888767/


All Articles