UITableViewCell Вопрос об анимации - PullRequest
0 голосов
/ 09 июля 2011

У меня есть UITableViewCell, и я пытаюсь добавить анимацию, которая заставляет слой прокручиваться от ячейки, проблема в том, что он обрезается ячейкой над ней, есть ли простой способ обойти это?

вот мой метод.

- (void)animateLife:(UIButton *)sender isPositive:(BOOL)state{

    // Reset lCount if we are pressing a different button than last time.
    if (sent != sender) {
        lCount = 0;
    }
    sent = sender;

    // Increase the count by 1.
    lCount = lCount + 1;

    // Set up some properties.
    CGPoint origin = sender.center;
    CGPoint newOrigin = CGPointMake(origin.x, (origin.y - 100));
    NSString *oper = [[NSString alloc] init];

    // Check to see if this is a + or - change.
    if (state == true) {
        oper = @"+";
    } else {
        oper = @"-";
    }

    // Alloc a String and a Label to hold it.
    NSString *characters = [[NSString alloc] initWithFormat:@"%@%d", oper, lCount];
    UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(origin.x,origin.y , 50, 50)];

    // Configure the Label.
    if (oper == @"-") {
        [theLabel setTextColor:[UIColor redColor]];
    } else {
        [theLabel setTextColor:[UIColor greenColor]];  
    }
    [theLabel setText:characters];
    [theLabel setBackgroundColor:[UIColor clearColor]];
    [theLabel setAlpha:1];
    [theLabel setCenter:origin];
    [theLabel setShadowColor:[UIColor blackColor]];
    [theLabel setShadowOffset:CGSizeMake(0.5, 0.5)];
    [theLabel setFont:[UIFont fontWithName:@"Helvetica" size:28]];
    [theLabel setTextAlignment:UITextAlignmentCenter];
    [theLabel.layer setShadowRadius:3];
    [theLabel.layer setShadowOpacity:0.9];

    // Display our Label.
    [sender.superview insertSubview:theLabel aboveSubview:sender];

    // Setup animation.
    [UIView beginAnimations:@"lifeCount" context:nil];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [theLabel setCenter:newOrigin];
    [theLabel setAlpha:0];

    // Commit Animation.
    [UIView commitAnimations];

    fCount = fCount + 1;
    // Clean up.
    [theLabel release];
    [characters release];
    [oper release];
}

- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    // Since an animation finished, reduce count by one.
    fCount = fCount - 1;

    //check if all animations are finished, if so, reset the lCount.
    if (fCount < 1) {
        lCount = 0;
    }
}

Обновление: появляется, если я прокручиваю ячейки до места их повторного использования, то анимация отображается правильно, есть ли способ, которым я могу сделать это, не требуя повторного использования?

1 Ответ

0 голосов
/ 09 июля 2011

В вашем методе cellForRowAtIndexPath, вероятно, есть такой код:

 cell = [tableView dequeueReusableCellWithIdentifier:someCellID];
 if ( cell == nil ) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:kCellID] autorelease];
 }

Не вызывайте метод "dequeueReusableCellWithIdentifier". Просто создайте новую ячейку каждый раз.

Обратите внимание, что если в таблице много строк, это приведет к снижению производительности.

...