0

I implemented a paging UIScrollView. Therefore I have got 5 subviews on my scrollview. To have a nice effect I set up a little offset to every subview so that on the first page, you can see a little bit of the second page at the right side of the ipad. The same effect on the other pages, so everytime you are on a page you have got a little preview on the left/right side of your screen. The scrolling between pages works perfect, but the problem is, that at the first time, the preview isn't loaded. I got a textview on every subview, but it loads first after I scroll to the next page. So my preview doesn't work correct. How can I do something like a preloading, so that my other subview pages are loaded before I switch to them?

Thanks for your help, I hope I could explain it that its clear... Andy

preview page loading

Code:

XIB: I have got one UIScrollView, Size 750, 700. My Customview is 700,700.

resultScrollView.clipsToBounds = NO;
resultScrollView.pagingEnabled = YES;
resultScrollView.showsHorizontalScrollIndicator = YES;

[resultScrollView addSubview:[self createCustomSubView:0.0f :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:2*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:3*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:4*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];

resultScrollView.contentSize = CGSizeMake(5*resultScrollView.frame.size.width+5*VIEW_OFFSET_BETWEEN, resultScrollView.frame.size.height);

The method:

CGRect frame = CGRectMake(contentOffset + betweenOffset, 0.0f, width, height);
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"CustomSubview" owner:self options:nil];
CustomSubview *customSubView = [subviewArray objectAtIndex:0];
CustomSubview.frame = frame;
CustomSubview.contentMode = UIViewContentModeCenter;
CustomSubview.contentSize = CGSizeMake(VIEW_SCROLLABLE_CONTENT_WIDTH, VIEW_SCROLLABLE_CONTENT_HEIGHT);
NDY
  • 3,527
  • 4
  • 48
  • 63
  • are the subviews just UIViews? – Kaan Dedeoglu Jul 20 '12 at 09:07
  • the subviews extend from UIScrollview, because every page should be vertically scrollable too. – NDY Jul 20 '12 at 09:14
  • I did the same offset trick to show a bit of the other subviews before, can you edit your post to show some code of how you're adding the subviews please ? – Kaan Dedeoglu Jul 20 '12 at 09:23
  • I did it. But I found out now that the problem is only the textview on my customview. As example, a label is preloaded and I can see it as a preview. But I think this code is like a hack, perhaps you have a better solution to do that? Because with my code I cant really change something easy, as example if I want to have more place between each subview, that doesnt work. And now I can only touch on my subviews - not between, because there is no scrollview. – NDY Jul 20 '12 at 09:36
  • I think you have to rethink how you're doing placing and setting up the main scrollView, as for only being able to touch the subview: http://stackoverflow.com/q/1220354/870155 – Kaan Dedeoglu Jul 20 '12 at 10:00

0 Answers0