我想在我的UITableViewCell中顯示動畫圈。我已經得到了以下代碼爲self.view工作,但是當我嘗試將它添加到cell.accessoryview時,它從不繪製。任何人有什麼想法,爲什麼它不顯示?將動畫圈添加到我的UITableViewCell中AccesoryView
- (void)makeCircleAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [_permanentSoundTableView cellForRowAtIndexPath:path];
// Set up the shape of the circle
int radius = 10;
circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
// Center the shape in self.view
circle.position = CGPointMake(cell.frame.size.width-10,cell.frame.size.height-5);
// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
UIColor *transparentBlack = [UIColor colorWithRed:250.0f green:250.0f blue:250.0f alpha:.5];
circle.strokeColor = transparentBlack.CGColor;
circle.lineWidth = 5;
// Add to parent layer
[cell.accessoryView.layer addSublayer:circle];
// Configure animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 8.0; // "animate over 10 seconds or so.."
drawAnimation.repeatCount = 1.0; // Animate only once..
drawAnimation.removedOnCompletion = NO; // Remain stroked after the animation..
// Animate from no part of the stroke being drawn to the entire stroke being drawn
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];
// Experiment with timing to get the appearence to look the way you want
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// Add the animation to the circle
[circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}
嘗試子類化單元 –
@Shan我真的不應該需要繼承細胞。你能提供其他建議嗎? – Apollo
通過繼承單元格可以在單元格上獲得更多的靈活性,對於單元格內的動畫我更喜歡子類化.. –