我正在尝试使用 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;
}
或
这可以帮助你更好
关于ios - 水平方向自动移动 UICollectionCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18186219/