搜尋

首頁  >  問答  >  主體

objective-c - 怎麼複製並旋轉在drawInContext裡面畫的圖。

畫了一個向上的箭頭,隨progress移動的,另一邊是對稱的,怎麼直接把轉過去。

-(void)drawInContext:(CGContextRef)ctx
{
    [super drawInContext:ctx];
    UIGraphicsPushContext(ctx);
    CGContextRef context=UIGraphicsGetCurrentContext();
    
    //draw
    
    //path1
    UIBezierPath *curvePath1=[UIBezierPath bezierPath];
    curvePath1.lineWidth=2.0f;
    //arrow path
    UIBezierPath *arrowPath=[UIBezierPath bezierPath];
    if (self.progress<=0.5) {
        CGPoint pointA=CGPointMake(self.frame.size.width/2-Radius, (2*LineLength-2*CenterY)*self.progress+2*CenterY);
        CGPoint pointB=CGPointMake(self.frame.size.width/2-Radius, (2*LineLength-2*CenterY)*self.progress+CenterY);
        //path
        [curvePath1 moveToPoint:pointA];
        [curvePath1 addLineToPoint:pointB];
        
        //arrow
        [arrowPath moveToPoint:pointB];
        [arrowPath addLineToPoint:CGPointMake(pointB.x-3*sinf(Degree), pointB.y+3*cosf(Degree))];
        [curvePath1 appendPath:arrowPath];
    }else if (self.progress>0.5){
        CGPoint pointA=CGPointMake(self.frame.size.width/2-Radius, 2*LineLength*self.progress+CenterY-2*LineLength);
        CGPoint pointB=CGPointMake(self.frame.size.width/2-Radius, CenterY);
        
        [curvePath1 moveToPoint:pointA];
        [curvePath1 addLineToPoint:pointB];
        [curvePath1 addArcWithCenter:CGPointMake(self.frame.size.width/2, CenterY) radius:Radius startAngle:M_PI endAngle:(2*M_PI*(1-self.progress)) clockwise:NO];
        
        [arrowPath moveToPoint:curvePath1.currentPoint];
        [arrowPath addLineToPoint:CGPointMake(curvePath1.currentPoint.x-3*(sinf(Degree+(2*M_PI*self.progress-M_PI))), curvePath1.currentPoint.y+3*cosf(sinf(Degree+(2*M_PI*self.progress-M_PI))))];
    }
    CGContextSaveGState(context);
    CGContextRestoreGState(context);
    
    [[UIColor blackColor] setStroke];
    [arrowPath  stroke];
    [curvePath1 stroke];
    
    UIGraphicsPopContext();
}
習慣沉默習慣沉默2757 天前469

全部回覆(0)我來回復

無回覆
  • 取消回覆