use*_*890 7 core-graphics rotation ios
通过这个公式,我得到了角度
double rotateAngle = atan2(y,x)
Run Code Online (Sandbox Code Playgroud)
使用此代码我可以绘制一个矩形
CGRect rect = CGRectMake(x,y , width ,height);
CGContextAddRect(context, rect);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
如何围绕角度旋转矩形?
Ste*_*eve 27
这是你如何做到这一点:
CGContextSaveGState(context);
CGFloat halfWidth = width / 2.0;
CGFloat halfHeight = height / 2.0;
CGPoint center = CGPointMake(x + halfWidth, y + halfHeight);
// Move to the center of the rectangle:
CGContextTranslateCTM(context, center.x, center.y);
// Rotate:
CGContextRotateCTM(context, rotateAngle);
// Draw the rectangle centered about the center:
CGRect rect = CGRectMake(-halfWidth, -halfHeight, width, height);
CGContextAddRect(context, rect);
CGContextStrokePath(context);
CGContextRestoreGState(context);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4753 次 |
最近记录: |