iOS around the rotation animation to achieve

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sinat_30657013/article/details/60961717

// transfer

DiyAnimation * circle = [[ DiyAnimationalloc] initWithFrame:CGRectMake(0,120, 320, 300)];

    [circle setDiyAnimationBackgroundColor:[UIColororangeColor]];

    [self.viewaddSubview:circle];



//DiyAnimation.h

-(void)setDiyAnimationBackgroundColor:(UIColor *)aColor;


//DiyAnimation.m

// create surround animation , passed two attributes are : angular movement started ( on the right 90 degrees to 0), the movement ending point of view

-(void)createCircle:(float)startAngle andEndAngle:(float)endAngle

{

    

    // create animated motion trajectory

    CAKeyframeAnimation * pathAnimation =, [ CAKeyframeAnimationanimationWithKeyPath:@"position"];

    pathAnimation. calculationMode = kCAAnimationPaced ;

    pathAnimation.fillMode =kCAFillModeForwards;

    pathAnimation.removedOnCompletion =NO;

    pathAnimation.duration =5.0;

    pathAnimation.repeatCount =MAXFLOAT;

    

    float x =20;

    // (11)  about the z -axis   (1 0) y (0 1 ) x (0 0) nil

    float radiuscaleOne = 1;

    float radiuscaleTwo = 1;

    // Center

    CGFloat origin_x =self.frame.size.width /2  ;

    CGFloat origin_y =self.frame.size.height /2 ;

    // 半径

    CGFloat radiusX =50;

    

    CGMutablePathRef ovalfromarc =CGPathCreateMutable();

    CGAffineTransform t2 =CGAffineTransformConcat(CGAffineTransformConcat(

                                                                          CGAffineTransformMakeTranslation(-origin_x, -origin_y),

                                                                          CGAffineTransformMakeScale(radiuscaleOne, radiuscaleTwo)),

                                                   CGAffineTransformMakeTranslation(origin_x, origin_y));

    

    CGPathAddArc(ovalfromarc, &t2, origin_x, origin_y, radiusX,startAngle,endAngle,1);// 1逆时针 0顺时针

    pathAnimation.path = ovalfromarc;

    CGPathRelease(ovalfromarc);

    // 圆形

    UIView * circleView1 = [[UIImageViewalloc] init];

    [selfaddSubview:circleView1];

    circleView1.frame =CGRectMake(160,130, x, x);

    [circleView1.layersetCornerRadius:x/2];

    circleView1.backgroundColor = [UIColoryellowColor];

    //设置运转的动画

    [circleView1.layeraddAnimation:pathAnimationforKey:@"moveTheCircleOne"];

    

    

}

//贝塞尔画出路径

- (void)drawRect:(CGRect)rect {

    CGFloat origin_x =self.frame.size.width/2;

    CGFloat origin_y =self.frame.size.height/2;


    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    

        //整个圆

    UIBezierPath *arc = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(origin_x -100, origin_y - 100,200, 200)];

    [[UIColorwhiteColor] setStroke];

    [arc stroke];

    CGContextRestoreGState(context);

}


-(void)setDiyAnimationBackgroundColor:(UIColor *)aColor

{

    self.backgroundColor = aColor;

    [selfcreateCircle: M_PI /6 andEndAngle:M_PI /6 + 2 *M_PI];


}

Guess you like

Origin blog.csdn.net/sinat_30657013/article/details/60961717