我正在用CAShapeLayer.On单点击画一个四分之一圆,我想把它转换成90 degree.But,图层正在转换,正在脱离屏幕,我需要围绕中心点旋转,假设中心点是(100,100)。这是我的代码:
CGMutablePathRef path = CGPathCreateMutable();
//CGPathMoveToPoint(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2);
CGPathAddArc(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2, 100, (0), (M_PI_2), NO);
CGPathAddArc(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2, 100-50, (M_PI_2), (0), YES);
CGPathCloseSubpath(path);
CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
arcLayer.path = path;
arcLayer.fillColor = [UIColor yellowColor].CGColor;
[self.layer addSublayer:arcLayer];动画代码:
CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spin.removedOnCompletion = NO;
spin.fillMode = kCAFillModeForwards;
[spin setByValue:[NSNumber numberWithFloat:M_PI_2]];
//layer.affineTransform = CGAffineTransformMakeRotation(M_PI_2);
[spin setDuration:1.0];
[layer addAnimation:spin forKey:@"transform.rotation"];请帮帮我。
发布于 2013-09-20 08:30:10
您所看到的问题之所以发生,是因为该层没有大小。您仍然可以看到路径,因为它没有被裁剪到层的边界。旋转是相对于层的中心应用的,但是在它自己的坐标系中没有(0,0)的大小(与路径使用的坐标系相同)。
通过设置一个强的背景色(而不是填充颜色)并给图层一个任意的框架,你可以明白我的意思。您想要的最后一个框架很可能是路径的边框。
此时,您应该看到视图围绕预期的点旋转。现在,您可以再次删除背景色。
发布于 2013-09-20 06:44:25
试着在动画之前设置图层的锚点。例:
layer.anchorPoint = CGPointMake(0.5f, 0.5f);(0,0)是层的左上角,(1,1)是右下角。
https://stackoverflow.com/questions/18909435
复制相似问题