gpt4 book ai didi

ios - 将动画圈添加到我的 UITableViewCell AccessoryView

转载 作者:行者123 更新时间:2023-11-29 03:27:36 25 4
gpt4 key购买 nike

我想在 UITableViewCell 中显示一个动画圆。我已经获得了以下代码,可用于 self.view,但是当我尝试将其添加到 cell.accessoryview 时,它永远不会绘制。有人知道为什么它不显示吗?

- (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"];
}

最佳答案

尝试在 cellForRowAtIndexPath: 方法中添加动画层,并确保单元格的 accessoryView 不是 nil。如果它是 nil,则添加带有动画层大小的空 UIView,然后添加层。祝你好运!

关于ios - 将动画圈添加到我的 UITableViewCell AccessoryView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20258670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com