1

私は持っていUITableViewます。セルがテーブルに読み込まれているときにアニメーションを作成したい。こんな感じにします。

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGRect tmpFrame;
    CGRect originalFrame;
    originalFrame = cell.frame;
    tmpFrame = cell.frame;
    tmpFrame = CGRectMake(0, -50, 320, 50);
    cell.frame = tmpFrame;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:5.0f];
    [UIView setAnimationBeginsFromCurrentState:YES];
    UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 1)];
    separatorLineView.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:separatorLineView];
    cell.frame = originalFrame;
    [UIView commitAnimations];
}

このコードはiOS6(iPhoneシミュレーター6)では正常に機能しますが、iOS 5.1(iPhoneシミュレーター5.1)では機能しません。

4

2 に答える 2

0

終わり。私はこのコードを

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

セルを返す前。

于 2013-02-15T10:30:50.037 に答える
0

ですから、あなたはすでに解決策を持っていることを知っていますが、古いバージョンと互換性を持たせているのでない限り、アニメーションブロックを使用することをお勧めします。とにかく、そうでない場合、これはアニメーションを書くための別の方法を提供するかもしれません。私はこの方法が好きです。何が起こっているのかをより細かく制御でき、混乱が少ないと感じているからです。

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell){
    cell = [[UITableViewCell alloc]init];
}

CGRect movementFrame = cell.frame; // set the movement frame for modification
movementFrame.origin.y -= 50; //adjust only one variable instead of making a rect..

//Start your animation block. 
[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseOut
                 animations:^{
                     //Animation here
                     cell.frame = movementFrame; // Commit your changes basically
                 } completion:^(BOOL finished) {
                     //Completeion c

                 }];

非常にすばらしい!気をつけて^^

編集

それをテストしに行って、私が重要な部分を省略していることに気づきました。申し訳ありませんが、このコードは機能し、セクションでいっぱいのページを持つグループ化されたテーブルでこのアニメーションを興味深いものにします。

于 2013-02-21T07:51:48.070 に答える