Lea*_*ros 3 core-graphics calayer cgcontext ios
我想UIView在我当前画一个CGGraphicsContext.我绘制了UIView通道renderInContext:,但它没有正确定位(始终位于左上角).
我有UIView可用于绘制的所有值UIView.
CGRect frame;
CGRect bound;
CGPoint center;
CGAffineTransform transform;
Run Code Online (Sandbox Code Playgroud)
我目前设置图层的位置和旋转,如下所示:
CGContextTranslateCTM(context, frame.origin.x, frame.origin.y);
CGContextRotateCTM(context, (CGFloat) atan2(transform.b, transform.a));
Run Code Online (Sandbox Code Playgroud)
但由于旋转,该位置不正确并且与原始位置不同.
我该如何恢复原来的位置?坐标系之间没有变化,将问题center.x和center.y价值转化为适合的问题只是一个问题CGContextTranslateCTM.
编辑:
保存的值是正确的,保存正确bounds,center并且transform不是我的问题的起源,我的问题的起源,是将这些值设置为drawable CGLayervia CGContextTranslateCTM.
Lea*_*ros 10
可以UIView使用以下代码段将图形上下文的几何图形调整为s几何图形:
// Center the context around the view's anchor point
CGContextTranslateCTM(context, [view center].x, [view center].y);
// Apply the view's transform about the anchor point
CGContextConcatCTM(context, [view transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[view bounds].size.width * [[view layer] anchorPoint].x,
-[view bounds].size.height * [[view layer] anchorPoint].y);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1645 次 |
| 最近记录: |