gpt4 book ai didi

ios - 水平方向自动移动 UICollectionCells

转载 作者:行者123 更新时间:2023-11-28 20:15:39 25 4
gpt4 key购买 nike

我正在尝试使用 UIView 制作动画但我想做的所有事情都是徒劳的。我需要 CollectionView Cells 应该在每隔固定秒数后自动水平滑动。

请帮我解决这个问题,因为这是我的应用等待发布的唯一原因。

我试过了,但没有成功。

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

if (collectionView == self.myCV) {
myCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];

if (cell == nil)
{

NSArray *xibPath = [[NSBundle mainBundle] loadNibNamed:@"myCollectionView" owner:self options:nil];
cell = [xibPath objectAtIndex:0];
}

// [myCV performBatchUpdates:^{
// [self.myCV reloadData];
// } completion: nil];
[UIView animateWithDuration:0.3f delay:0.0 options:0 animations:^{
[self.myCV scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.section inSection:0]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:NO];
} completion:^(BOOL finished) {
NSLog(@"Completed");
}];

return cell;



}

谢谢,*最好的问候。*

最佳答案

如果你的移动代码有效,那么在定时器函数中使用它,间隔为 1 秒

[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(targetMethod)
userInfo:nil
repeats:YES];

-(void)targetMethod
{

[self.myCV scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:0]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];

rowIndex=(rowIndex<noOfRows-1)?(rowIndex+1):0;

}

这可以帮助你更好

https://stackoverflow.com/a/13129472/1305001

关于ios - 水平方向自动移动 UICollectionCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18186219/

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