ios - UICollectionView scrollToItemAtIndexPath 单元格在半隐藏时消失

标签 ios iphone objective-c uicollectionview uiviewanimation

我正在尝试自动移动我的 UICollectionView 中的单元格.移动它的代码:

- (void)scroll {
    row += 2;
    [UIView animateWithDuration:1.f
                          delay:0.f
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
                     }
                      completion:^(BOOL finished) {
    }];
}

我的单元格以 2 行模式水平组织:
|cell||cell||cell|->etc
|cell||cell||cell|->etc

问题是当滚动移动到下一个单元格时,整个 collectionView 移动,前一个单元格消失。它恰好发生在前一个单元格的一半在屏幕上不可见时。为什么会发生?知道如何解决这个问题吗?

它看起来像:(〜表示屏幕)
step 1:
~|cell||cell||cell|~
~|cell||cell||cell|~

step 2:
~ell||cell||cell||c~
~ell||cell||cell||c~

step 3:
~ll||cell||cell||ce~
~ll||cell||cell||ce~

step 4:
~  |cell||cell||cel~ --> here first cell disappears even though
~  |cell||cell||cel~ --> there is enough space for it

更重要的是,代表:collectionView:didEndDisplayingCell:forItemAtIndexPath:当单元格是半可见时被调用(所以正好在步骤 3 和 4 之间)

最佳答案

好的,因此无法在此上制作动画 - 单元格出列的速度太快了。而不是这种方法,我使用了这样的东西:

_timer = [NSTimer scheduledTimerWithTimeInterval:0.02f target:self selector:@selector(scroll) userInfo:nil repeats:YES];


- (void)scroll {
    tmp += 1;
    _collectionView.contentOffset = CGPointMake(tmp, 0);
}

关于ios - UICollectionView scrollToItemAtIndexPath 单元格在半隐藏时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20115729/

相关文章:

ios - UILabel 的字体颜色没有改变

iphone - NSString 到 NSDate 不适用于 iDevice

iphone - 仅通过蓝牙设置 iPhone P2P,不使用 GKPeerPickerController

iphone - ARC 和 ASIHTTPRequest

ios - Objective-C:在文件中保存/还原复杂数据的数据结构?

ios - swift UITableView 设置行宽

ios - Objective C 内存布局 : Meaning of the highest 2 bits of a 64bit pointer?

objective-c - 如何使用 PKRevealController 切换 Front View Controller?

iphone - 如何在 iOS 应用程序中嵌入 Flash 文件

ios - Game Center 应该是可选的吗?