Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableViewCell动画问题_Iphone_Objective C_Uitableview_Core Animation - Fatal编程技术网

Iphone UITableViewCell动画问题

Iphone UITableViewCell动画问题,iphone,objective-c,uitableview,core-animation,Iphone,Objective C,Uitableview,Core Animation,我有一个UITableViewCell,我正在尝试添加一个动画,它会导致一个层从单元格中滚动出去,问题是它会被上面的单元格剪切掉,有没有一个简单的方法来解决这个问题 这是我的方法 - (void)animateLife:(UIButton *)sender isPositive:(BOOL)state{ // Reset lCount if we are pressing a different button than last time. if (sent != sender

我有一个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;
    }
}

更新:如果我将单元格滚动到可重用的位置,则会出现动画,动画会正确显示。有没有办法使其不需要重用?

在方法CellForRowatineXpath中,可能有如下代码:

 cell = [tableView dequeueReusableCellWithIdentifier:someCellID];
 if ( cell == nil ) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:kCellID] autorelease];
 }
不要调用dequeueReusableCellWithIdentifier方法。每次只需创建新的单元格


请注意,如果您的表中有很多行,这将影响性能。

我有点希望找到一种方法来修改我的[sender.superview insertSubview:theLabel oversubview:sender];使其位于所有其他层之上[sender.superview将子视图带到前面:标签];或标签layer.zPosition=0;是的,这也行不通:肯定有办法做到这一点。