CAShapeLayer 的缩放问题(transform.scale)
{
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
btn.backgroundColor = [UIColor grayColor];
btn.layer.cornerRadius = 50;
[self.view addSubview:btn];
[btn addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside];
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 100, 100) cornerRadius:50];
layer = [CAShapeLayer layer];
layer.path = [path CGPath];
layer.fillColor = [[UIColor clearColor] CGColor];
layer.lineCap = kCALineCapRound;
layer.lineWidth = 1.0;
layer.strokeColor = [[UIColor redColor] CGColor];
[btn.layer addSublayer:layer];
}
-(void)clicked
{
NSLog(@"clicked");
CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
anim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(3, 3, 1)];
anim.duration = 3.0;
[layer addAnimation:anim forKey:@"animateTransform"];
}
一个按钮,圆形的,按钮的layer上放置了一个 CAShapeLayer,填充为透明,边框为红色的。
按钮点击的时候,边框从按钮的中心点向四周放大。
现在的现象是,layer居然往右下角放大移动,并且边框大小也变大了。
请问我的代码哪里出现了问题?
谢谢~~~