0
私はUITableViewCellのを持っている、と私は、細胞の外にスクロールする層の原因となるアニメーションを追加しようとしています、問題は、それはそれより上の細胞によって切り取られますされ、周りを取得する簡単な方法がありますこの?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;
}
}
更新:私はそれが再利用を必要としないことができます方法がある私は、彼らが再利用されますどこに細胞をスクロールする場合、アニメーションが正しく表示さ現れますか?あなたの方法のcellForRowAtIndexPathで
ちょっと私の[sender.superview insertSubview:theLabel aboveSubview:送信者]を変更する方法を望んでイム。それを他のすべてのレイヤーの上に移動させます。 – Weston
[sender.superview bringSubviewToFront:theLabel];または theLabel.layer.zPosition = 0; – Rayfleck
どちらもうまくいきませんね:(確かにこれを行う方法がなければなりません。 – Weston