0

I have this code: it's for 3 scroll view to have a random paging

CGRect frame = scrollView.frame;
CGRect frame1 = scrollView1.frame;
CGRect frame2 = scrollView2.frame;
frame.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame.origin.y = 0;
frame1.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame1.origin.y = 0;
frame2.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame2.origin.y = 0;

int pageFirst = scrollView.contentOffset.x/scrollView.frame.size.width;
int pageSecond = scrollView1.contentOffset.x/scrollView1.frame.size.width;
int pageThird = scrollView2.contentOffset.x/scrollView2.frame.size.width;

my problem is that when I launch my app nslog values for pageFisrt, pageSecond and PageThird is ever equal but paging is random and different; how can I have the correct value of pagefirst, pageSecond and pageThird?

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
  • Can you give some more detail as to what you are actually trying to achieve. It's not very clear from your question. What do you mean by '3 scroll view to have a random paging' – Ashley Mills Sep 29 '11 at 13:35
  • when I launch my app I call this method that make a scroll random of my 3 scroll view and I want to know the index of every page. But the nslog give me in all 3 result the same index, at the example if I have in scrollView page 2, in scrollview1 page 4 and in scrollview2 page0, the nslog write the same index, as 1,1,1 or 0,0,0 – cyclingIsBetter Sep 29 '11 at 14:25

1 Answers1

0

You are setting the frame of your 3 scroll views which will position the 3 scrollViews at random places in their superview - this does not affect the contentOffset.

It looks as though what you meant to do was

scrollView.contentOffset = (CGPoint){scrollView.bounds.size.width * (arc4random() % (arrayimage.count )), 0};

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160