【问题标题】:UICollectionView scrollToItemAtIndexPath cell disappears when half hiddenUICollectionView scrollToItemAtIndexPath 单元格在半隐藏时消失
【发布时间】:2013-11-21 17:20:00
【问题描述】:

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

【问题讨论】:

    标签: ios iphone objective-c uicollectionview uiviewanimation


    【解决方案1】:

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

    _timer = [NSTimer scheduledTimerWithTimeInterval:0.02f target:self selector:@selector(scroll) userInfo:nil repeats:YES];
    
    
    - (void)scroll {
        tmp += 1;
        _collectionView.contentOffset = CGPointMake(tmp, 0);
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多