29,028
社区成员
发帖
与我相关
我的任务
分享
在viewDidLoad里面
CGRect rect = CGRectMake(220,40,40,40);
_btn = [[UIButton alloc]initWithFrame:rect];
_btn.layer.cornerRadius = 40/2;
_btn.backgroundColor = [UIColor redColor];
[self.view addSubview:_btn];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-(void)startAnim
{
//
CGRect rect = CGRectMake(x, y, 100*2, 100*2);
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(rect, NULL));
orbit.duration = 4;
orbit.additive = YES;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
[_btn.layer addAnimation:orbit forKey:@"orbit"];
}
CGPoint arcCenter=CGPointMake(240,160);
int radius = 100;
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:radius startAngle:DEGREES_TO_RADIANS(270)
endAngle:DEGREES_TO_RADIANS(-90)
clockwise:NO];
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path =circlePath.CGPath;
orbit.duration = 4;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
[_btn.layer addAnimation:orbit forKey:@"orbit"];