开发者

RotateCTM makes graphics disappear, Quartz 2D

开发者 https://www.devze.com 2023-03-15 20:38 出处:网络
First off, I am a quartz 2d noob.I have a pie chart, and basically want to make a line coming out of it diagonally, in the northeast quadrant, then go horizontal to the right, and have a label explain

First off, I am a quartz 2d noob. I have a pie chart, and basically want to make a line coming out of it diagonally, in the northeast quadrant, then go horizontal to the right, and have a label explaining what that section is. So, I have this code that draws the diagonal line. The line draws to the southeast. I expect that based on the iPhone origin being in the northwest quadrant. So I thought I could rotate my CTM first by 3pi/2, and then have that same code work. However, when I uncomment the CGContextRotateCTM() line, I get no line. I'm not sure what is happening here and where the logic error is. Thanks.

   CGPoint circleCenter = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);   
    CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, LINE_WIDTH);
    CGContextBeginPath(context);
//    CGContextRotateCTM(context, 3 * M_PI / 2);
    CGContextMoveToPoint(context, circleCenter.x + self.CircleRadius / 2, circleCenter.y + self.CircleRadius / 2);
    CGContextAddLineToPoint(context, c开发者_如何学运维ircleCenter.x + self.CircleRadius / 2 + LINE_LENGTH, circleCenter.y + self.CircleRadius / 2 + LINE_LENGTH);
    CGContextStrokePath(context);


It seems you are rotating your line out of sight. Always keep the center in mind that you rotate around - maybe also translate your CTM first.

Edit: To check, you might want to try very small rotations incrementally and watch where your line goes.

0

精彩评论

暂无评论...
验证码 换一张
取 消