好的,这是我的问题,
假设您的方位角为 80 度。我想用一个简单的 10x10 正方形在 iPhone 屏幕上绘制出来。让我们假设纵向模式下 iPhone 的顶部是北方。
关于我将如何实现这一点有什么想法吗?
顺便说一句 - 我不想使用以下方法:
CGAffineTransform where = CGAffineTransformMakeRotation(degreesToRadians(x_rounded));
[self.compassContainer2 setTransform:where];
我想通过在 iPhone 屏幕上设置 X-Y 线来在屏幕上手动绘制。
最佳答案
- (void)drawRect:(CGRect)rect
{
float compass_bearing = 80.0; // 0 = North, 90 = East, etc.
CGContextRef theContext = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 5.0, 5.0);
CGPathAddLineToPoint(path, NULL,
5.0 + 5.0 * cos((compass_bearing - 90.0) * M_PI / 180.0),
5.0 + 5.0 * sin((compass_bearing - 90.0) * M_PI / 180.0));
CGContextSetLineWidth(theContext, 2.0);
CGContextSetStrokeColorWithColor(theContext, [UIColor blackColor].CGColor);
CGContextAddPath(theContext, path);
CGContextStrokePath(theContext);
CGPathRelease(path);
}
关于objective-c - 在 iPhone 屏幕上绘制罗盘方位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11110348/