Objective c 如何在UIImageView中的特定点定位旋转层?
我有下面的代码,它使一个椭圆围绕它的中心旋转。我希望能够将它放置在Objective c 如何在UIImageView中的特定点定位旋转层?,objective-c,ios,core-animation,cashapelayer,Objective C,Ios,Core Animation,Cashapelayer,我有下面的代码,它使一个椭圆围绕它的中心旋转。我希望能够将它放置在UIImageView中的某个位置(比如视图的中间) 如果有人能帮我解决这个问题,我会非常感激 -(void)drawCircle { CGMutablePathRef circlePath = CGPathCreateMutable(); int radius = 400; CGRect circleRect = CGRectMake(CENTER_Y-radius*0.7, CENTER_X-radius, 1.4*radiu
UIImageView
中的某个位置(比如视图的中间)
如果有人能帮我解决这个问题,我会非常感激
-(void)drawCircle
{
CGMutablePathRef circlePath = CGPathCreateMutable();
int radius = 400;
CGRect circleRect = CGRectMake(CENTER_Y-radius*0.7, CENTER_X-radius, 1.4*radius, 2*radius);
float midX = CGRectGetMidX(circleRect);
float midY = CGRectGetMidY(circleRect);
CGAffineTransform transform = CGAffineTransformMakeTranslation(-midX, -midY);
CGPathAddEllipseInRect( circlePath ,&transform , circleRect);
CAShapeLayer *circle = [[CAShapeLayer alloc] init];
circle.path = circlePath;
circle.opacity = 0.1;
circle.contentsScale = SCREEN_SCALE;
circle.fillColor = [UIColor blueColor].CGColor;
[aView.layer addSublayer:circle];
CABasicAnimation* theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
theAnimation.fromValue = 0;
theAnimation.toValue = @(2*M_PI);
theAnimation.duration=3.5;
theAnimation.autoreverses=FALSE;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.fillMode = kCAFillModeBoth;
theAnimation.removedOnCompletion=FALSE;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[circle addAnimation:theAnimation forKey:@"transform.rotation.z"];
}
缺少的一块:
[circle setPosition:CGPointMake(CENTER_X, CENTER_Y)];
这是问题的一部分还是你问题的实际答案?当然,这是问题的额外信息。您应该编辑问题,而不是在答案中发布更多信息。(问题左下角的编辑按钮)这是我问题的答案。看起来你也忽略了设置形状层的边界<代码>[circle setBounds:circleRect]代码>所以我很惊讶它居然会显示出来。