当收集子视图的大小增加时,应用程序运行速度较慢?

时间:2013-08-27 18:52:20

标签: iphone ios objective-c performance uicollectionview

我正在为我的通用应用程序使用UICollectionView。在每个集合视图单元格内部,我有一个自定义视图,最终保存一个图像。每个单元格代表一张扑克牌,所以当点击时它会从前向后翻转。我遇到的问题是当我扩大该子视图的大小时。如果我在单元格中将它缩小,那么一切都运行良好。没有任何减速。如果我然后将该子视图放大到更大,则会出现严重的减速。不仅在我向上滚动集合视图时,还在我点击单个单元格时。当一排电池来自屏幕外时会发生滞后。当我点击“卡片”并且从前到后翻转时,也会出现延迟。

此问题似乎仅存在于应用的iPad版本上。当我在iPhone上运行时,就滞后而言完全没有问题。

为什么会发生这种情况有什么理由吗?

编辑以添加代码:

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

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Card" forIndexPath:indexPath];

    Card *card = [self.game getCardFromPlayAtIndex:indexPath.item];

    [self updateCell:cell usingCard:card withAnimation:NO];


    return cell;
}

上面使用的抽象方法:

- (void)updateCell:(UICollectionViewCell *)cell usingCard:(Card *)card withAnimation:(BOOL)isAnimated
{
    // Using introspection to make sure that our cell is a PlayingCardCollectionViewCell
    if ([cell isKindOfClass:[PlayingCardCollectionViewCell class]]) {

        // If it is we an take that cell and cast it to a PCCVC and then pull out it's
        // outlet for the PlayingCardView
        PlayingCardView *playingCardView = ((PlayingCardCollectionViewCell *)cell).playingCardView;

        if ([card isKindOfClass:[PlayingCard class]]) {
            PlayingCard *playingCard = (PlayingCard *)card;

            playingCardView.rank = playingCard.rank;
            playingCardView.suit = playingCard.suit;


            playingCardView.faceUp = playingCard.isFaceUp;

            playingCardView.alpha = playingCard.isUnplayable ? 0.3 : 1.0;
        }

    }

}

0 个答案:

没有答案