【发布时间】:2014-04-23 13:10:19
【问题描述】:
我正在编写一份简报,其中涉及构建一个包含许多锻炼和练习的水平滚动视图。
我已经走上了在 UIView 中使用 UICollectionView 的路线,因为这听起来很适合我的需要。
我已经有一个水平滚动的视图来显示我的自定义单元格 - 我的问题是当页面滚动时它似乎滚动不足 - 即它将滚动小于页面宽度 - 所以如果我有 6到我的视图中途时的页面不同步(偏离中心)-
我的第二个问题是,虽然我的视图水平滚动 - 我无法垂直滚动以查看所有单元格。 - 我怎样才能让它工作?
我的代码如下——
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;
}
故事板设置截图 -
【问题讨论】:
标签: ios objective-c uicollectionview