recherche

Maison  >  Questions et réponses  >  le corps du texte

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 Il y a quelques jours474

répondre à tous(0)je répondrai

Pas de réponse
  • Annulerrépondre