I am working to a brief which involves building a horizontally scrolling view which contains a number of workouts and exercises.
I have gone down the route of using a UICollectionView within a UIView as this sounded like it would suit my needs.
I have got as far as having a horizontally scrolled view which shows my custom cell - my issue is that when the page scrolls it seems to under-scroll - ie it will scroll less than the page width - so if I have 6 pages by the time I get midway through my view is out of sync (off center) -
my second problem is that although my view scrolls horizontally - I cant scroll vertically to see all cells. - how can I get this to work?
My code is as follows -
WO_SessionVC.H
#import <UIKit/UIKit.h>
#import "BG_Blur_ViewController.h"
@interface WO_SessionVC : BG_Blur_ViewController <UICollectionViewDelegate,
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *colView;
@property (weak, nonatomic) IBOutlet UIPageControl *pager;
@end
WO_SessionVC.M
#import "WO_SessionVC.h"
#import "WOColView.h"
@interface WO_SessionVC ()
@end
@implementation WO_SessionVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_pager.numberOfPages = 9;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return 9;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGFloat pageWidth = _colView.frame.size.width;
_pager.currentPage = _colView.contentOffset.x / pageWidth;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Dequeue a prototype cell and set the label to indicate the page
WOColView *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"CellWO"
forIndexPath:indexPath
];
return cell;
}
Storyboard settings screenshot -