我有一个目前提供六项的UICollectionView设置UICollectionViewDataSource.这些比填充屏幕所需的少.问题是我的集合视图仅在有足够的项目填充屏幕时滚动(用10,20测试).当显示较少的项目时,它甚至不会做我试图获得的反弹动画,它只是修复.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCollectionViewData) name:UIDocumentStateChangedNotification object:nil];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.itemSize = CGSizeMake(160, 100);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.bounces = YES;
[self.view addSubview:self.collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionViewData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Expense *expense = [self.collectionViewData objectAtIndex:indexPath.row];
UILabel …Run Code Online (Sandbox Code Playgroud) 我正在使用UICollectionView,它显示的项目少于填充整个屏幕所需的项目.使用此设置,视图根本不会滚动(移动和反弹),当我添加20个项目时,它可以工作.
如何强制集合视图滚动,没有足够的项目来填充屏幕?
http://bytolution.com/Screenshot%202013.04.17%2021.57.00.png
谢谢你的帮助!
顺便说一下,我已经尝试设置contentSize(例如设置为{320,1000})但它仍然不起作用.
我试图在我的iPhone应用程序中嵌入一个简单的视图来快速拍摄快照.一切正常,但我在摄像机启动时遇到了一些问题.在Apple示例项目中,AVCaptureSession -startRunning没有在主线程上执行,似乎是必要的.我在视图初始化期间设置捕获会话,并在单独的线程中启动它.现在,我添加了AVCaptureVideoPreviewLayer在-didMoveToSuperview.没有多线程的一切都很好(UI被阻止了大约一秒钟)但是使用GCD时,UI有时可以正常工作,有时候UI需要太长时间才能"解冻"或显示预览.
如何在不阻塞主线程的情况下以可靠的方式处理摄像机的启动延迟(延迟本身不是问题)?
我希望你们明白我的问题:D
提前致谢!
BTW:这是我的概念验证项目(没有GCD)我现在正在重用另一个应用程序:http://github.com/dariolass/QuickShotView
我目前正在尝试实现一个简单的两行UICollectionView.因为在使用涉及Core Data的更复杂数据源时我已经遇到过这个问题,所以我只使用了包含一些字符串的NSArray.问题仍然是一样的.
- (NSArray *)collectionViewData
{
return @[@"zero",@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",@"nine",@"ten",@"eleven",@"twelve",@"thirteen",@"fourteen",@"fifteen",@"sixteen", @"seventeen"];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!self.collectionView) {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.itemSize = CGSizeMake(160, 120);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 10;
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
self.collectionView.dataSource = self;
[self.collectionView registerClass:[BYCollectionViewCell class] forCellWithReuseIdentifier:@"CELL_ID"];
[self.view addSubview:self.collectionView];
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.collectionViewData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BYCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL_ID" forIndexPath:indexPath];
cell.title = self.collectionViewData[indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
http://bytolution.com/scrnsht.png
如您所见,单元格的顺序错误.当我将其设置minimumLineSpacing …