1

誰かがアニメーションをAQGridViewCellsに適用することに成功しましたか?私はすべてのセルを作成しようとしていますが、最初のセルはタップすると消えてしまいます。

問題は、フェードが始まると、通常、セルの内容が入れ替わるということです。たとえば、グリッドビューの最初の行に「1」、「2」、「3」のラベルが付いたセルがある場合、ラベルは「1」、「3」、「2」にスワップされる可能性があります。

- (AQGridViewCell *)gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index
{
    static NSString *CellIdentifier = @"ReusableGridViewCell";

    AQGridViewCell *cell = (AQGridViewCell *)[gridView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"ReusableGridViewCell" owner:self options:nil];

        cell = [[[AQGridViewCell alloc] initWithFrame:gridViewCellContent.frame
                                      reuseIdentifier:CellIdentifier] autorelease];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        [cell.contentView addSubview:label];
        [label release];

        cell.selectionStyle = AQGridViewCellSelectionStyleNone;
    }

    UILabel *label = [[cell.contentView subviews] objectAtIndex:0];
    if (! tapped)
    {
        label.text = [NSString stringWithFormat:@"%u", index];
    }   
    else if (index > 0)
    {
        CATransition *cellAnimation = [CATransition animation];
        cellAnimation.duration = 3.0;
        cellAnimation.type = kCATransitionFade;
        cellAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
        [label.layer addAnimation:cellAnimation forKey:kCATransition];              // labels get swapped
//      [cell.contentView.layer addAnimation:cellAnimation forKey:kCATransition];   // labels get swapped
//      [cell.layer addAnimation:cellAnimation forKey:kCATransition];               // labels get swapped, one cell immediately disappears
        NSLog(@"%u", [gridView isAnimatingUpdates]);                                // prints "0"

        label.hidden = YES;
    }

    return cell;
}

- (void)gridView:(AQGridView *)aGridView didSelectItemAtIndex:(NSUInteger)index
{
    tapped = YES;
    [gridView reloadData];
}

AQGridView、、などのメソッドの束にブレークポイントを設定してAQGridViewCell、スワップの原因となるメソッドを見つけようとしました。見つかりませんでした。

の既知のバグにはAQGridView、次のようなものがあります。

複数のアニメーションを積み重ねようとしないでください。つまり、-isAnimatingUpdatesメソッドがYESを返すグリッドビューで-beginUpdatesを呼び出さないでください。悪いことが起こり、細胞は間違った場所に行き着き、互いに積み重なってしまいます。

上記のコードでは、を-isAnimatingUpdates返しますNO。それでも、おそらく私が見ているのは、別の関連するバグですAQGridView-バグレポートを提出します。しかし、私のものは非常に単純なケースなので、誰かが以前にそれに遭遇し、回避策を考え出したのではないかと思います。おそらく、内部のアニメーションをオフにする何らかの方法ですAQGridView

編集

問題がhiddenプロパティに関連しているかどうかを確認するために、代わりにセルの不透明度をアニメーション化しました(ここで説明する両方のアプローチを試しました)。不透明度が0.0ではなく0.5に下がった場合でも、セルはスワッピングしています。

4

1 に答える 1

1

回避策は次のとおりです。誰かがもっとエレガントな解決策を見つけたら、私はそれを答えとしてマークします。

- (void)gridView:(AQGridView *)aGridView didSelectItemAtIndex:(NSUInteger)index
{
    // Create a copy of the 0th cell's content and display it on top of that cell.
    AQGridViewCell *selectedCell = [aGridView cellForItemAtIndex:0];
    UILabel *selectedLabel = [[selectedCell.contentView subviews] objectAtIndex:0];
    CGRect frame = [self.view convertRect:selectedLabel.frame fromView:selectedLabel.superview];
    UILabel *labelOnTop = [[UILabel alloc] initWithFrame:frame];
    labelOnTop.text = selectedLabel.text;
    [self.view addSubview:labelOnTop];
    [labelOnTop release];

    // Fade away the grid view as a whole (not individual cells). 
    CATransition *cellAnimation = [CATransition animation];
    cellAnimation.duration = 3.0;
    cellAnimation.type = kCATransitionFade;
    cellAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    [aGridView.layer addAnimation:cellAnimation forKey:kCATransition];
    aGridView.hidden = YES;
}
于 2011-12-12T16:13:40.017 に答える