ios - 水平方向自动移动 UICollectionCells

标签 ios animation uicollectionview uicollectionviewcell

我正在尝试使用 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/

相关文章:

ios - ipad:为什么我的连续动画的第一个动画总是立即完成?

html - 使用 CSS 过渡淡出菜单的不透明度

ios - 快速 fatal error 中的自定义 CollectionViewCell

ios - 如何将 subview 添加到自定义 UICollectionViewCell

ios - 'NSInternalInconsistencyException',原因 : 'Unexpected subviews' possibly in UIPageViewController (swift, iOS)

objective-c - 如何制作类似 Explore Flickr 应用旋转动画的动画

ios - UIWebView全屏播放HTML5视频,触摸不再被识别

WPF 3D Blend 教程和示例

ios - 如何在 App Store 中创建类似特色页面的布局?

ios - 如果可用,将项目添加到特定 TableView 行