Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright ready for this hotness?</p> <p>So in my main view controller's viewDidLoad I identify the views to load into the uicollectionview cells in an array: </p> <pre><code>NSArray *vcs = [@"view5", @"view1", @"view2", @"view3", @"view4", @"view5", @"view1"] </code></pre> <p>I also set our pagecontrol count to:</p> <pre><code>self.pageControl.numberOfPages = vcs.count - 2; // for the fake first and last cells </code></pre> <p>I then instantiate the viewcontrollers in the main view controller's viewDidLoad as well as set the alpha for the collectionview to 0. Then in our scrollViewDidEndDecelerating I handle the Carousel (go from last cell to first and first cell to last) and updating the pageControl to reflect the "real" page number.</p> <pre><code>- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // Snaps into the cell CGFloat pageWidth = scrollView.frame.size.width; float fractionalPage = scrollView.contentOffset.x / pageWidth; NSInteger page = lround(fractionalPage); self.pageControl.currentPage = page - 1; // because our first cell is the last cell for animation purposes only // Carousel from first to last and last to first while updating pagecontrol if (page == 0) { [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.activeGaugeClusters.count - 2 inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; // Set our pagecontrol circles to the appropriate page indicator self.pageControl.currentPage = self.activeGaugeClusters.count - 2; } else if (page == self.activeGaugeClusters.count -1) { [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; self.pageControl.currentPage = 0; } } </code></pre> <p>Then in the collectionview implementation I do the following:</p> <pre><code>numberOfItemsInSection = vcs.count </code></pre> <p>and viewDidAppear for loading the first cell (whether it is the cell at indexPath.row == 1 or 2 or 3... (1 being the first real page not 0)</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.lastGaugePanel inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; self.pageControl.currentPage = self.lastGaugePanel - 1; [UIView animateWithDuration:0.5 animations:^{ self.collectionView.alpha = 1.0; }]; } </code></pre> <p>I think that about sums it up. The rest of the implementations for both the main vc and the collectionview are standard. So now I have a collection view that loads up other views and their VCs that each have their own animation or whatever. I save the indexPath.row to NSUserDefaults so that the cell that I was in when I leave is the first cell to show on the next load.</p> <p>Hopes this helps someone, I know it did for me, unfortunately the use of 3rd party libraries was discouraged so I had to build this bad boy up (with help from @He Was, thanks again!)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload