Tôi đang cố gắng tạo hiệu ứng cho chiều rộng của hình chữ nhật tròn, vấn đề là khi đi từ chiều rộng lớn hơn đến chiều rộng mỏng hơn, hoạt ảnh sẽ thực hiện "nhảy dễ dàng sai".(iOS) Làm thế nào để animate hình chữ nhật tròn với shapeLayer?
Dưới đây là các mã:
shapeLayer = [CAShapeLayer layer];
shapeRect = CGRectMake(0.0f, 0.0f, 150.0f, 200.0f);
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake(iniPosX, 80.0f)];
[shapeLayer setFillColor:[[UIColor blackColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor clearColor] CGColor]];
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setOpacity:0.2];
path = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:15.0];
[shapeLayer setPath:path.CGPath];
[self.layer addSublayer:shapeLayer];
Và khi tôi bắt đầu hoạt hình:
- (void)adjustSelectorToPosAndSize:(float)posX andWidth:(float)width
{
shapeRect = CGRectMake(0.0f, 0.0f, width, 200.0f);
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake(posX, 80.0f)];
path = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:15.0];
[shapeLayer setPath:path.CGPath];
}
Tôi đang làm gì sai?
Cảm ơn sự điều chỉnh của Alexis. – murb83