gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:45:45 26 4
gpt4 key购买 nike

我正在尝试自动移动我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com