- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在屏幕上有四个随机位置的小圆圈。这些小圆圈可以在屏幕上的任何位置,并且位于 MapView 的前面。
如何根据这些圆圈创建形状?
此外,用户可以按一个按钮来随机更改圆圈的位置,因此必须重新创建形状。
到目前为止,我正在阅读有关 UIBezierPath 的信息,并且我能够基于点创建一个形状,但我无法动态地进行操作。
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint: CGPointMake(52, 33)];
[bezierPath addLineToPoint: CGPointMake(145, 19)];
[bezierPath addLineToPoint: CGPointMake(158, 79)];
[bezierPath addLineToPoint: CGPointMake(66, 103)];
[UIColor.grayColor setFill];
[bezierPath fill];
最佳答案
您可以做的是添加 UIImageView
使用透明背景颜色作为 MapView
的 subview ( ImageView 应该与您的 map View 具有相同的框架)。
在 viewDidLoad
,你可以开始一个 imageContext,使用:UIGraphicsBeginImageContext(self.imageView.frame.size)
然后,您可以使用 CGMutablePath
在您的点之间画线。 :
func drawLines()
{
let point1 = CGPointMake(20, 100)
let point2 = CGPointMake(230, 150)
let point3 = CGPointMake(40, 340)
let points = [point1, point2, point3]
let context = UIGraphicsGetCurrentContext()
CGContextClearRect(context, self.imageView.frame)
let pathRef = CGPathCreateMutable();
for var i = 0; i < points.count; i++
{
let point = points[i]
if i == 0
{
CGPathMoveToPoint(pathRef, nil, point.x, point.y)
}
else
{
CGPathAddLineToPoint(pathRef, nil, point.x, point.y)
}
}
CGContextSetLineWidth(context, 5.0)
CGPathCloseSubpath(pathRef)
CGContextAddPath(context, pathRef);
CGContextSetStrokeColorWithColor(context, UIColor.brownColor().CGColor)
CGContextStrokePath(context)
let image = UIGraphicsGetImageFromCurrentImageContext()
self.imageView.image = image
}
关于ios - 基于CGPoint在屏幕上绘制UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35385938/
在我的应用程序中,我有两个按钮和一个每秒触发一个操作的计时器。每秒,它生成四个随机数。这些数字用作按钮的 X 和 Y 值,并且按钮移动到新的点。然而,有时新点很接近,因此按钮会重叠。我如何检查以确保不
我计算两个 CGPoint 之间的角度: //calculate radian and degree CGPoint diff = ccpSub(center, locatio
我想在两点之间的弧线上显示图像。我有一个起始 CGPoint 和一个结束 CGPoint。我已经使用 SceneKit 和其他生成整个拱门和图表的答案看到了类似这样的答案。我只是在常规 View 中工
好的,我想将 CGPoint(A) 围绕 CGPoint(B) 旋转 50 度,有什么好的方法吗? CGPoint(A) = CGPoint(x: 50, y: 100) CGPoint(B) = C
我正在生成一些位置随机的圆圈。我要防止的是圆圈相互重叠。所以我想将新生成的 CGPoint 值与数组中的值进行比较,如果该值位于其中一个 CGPoint 的半径区域中,则让它生成一个新值。 除了重叠的
我有一个使用函数 addCurveToPoint 由 CGPoint 数组组成的 UIBezierPath,这里是一些代码: UIBezierPath *path = [[UIBezierPath a
我正在尝试使用两个 UIButton。一个距离它们所在的 UIView 边缘 8 点,第二个距离第一个开始 4 点。我现在正在做这个 let buttonFrames: CGSize = CG
我有一个使用 Core Graphics 的绘图应用程序。一切正常。我会画画。我添加了一个“撤消”按钮来撤消该行。它有效,但是...... 问题:每次按下“撤消”按钮时,它都会逐行删除。我正在尝试将
我找到了将 X、Y 转换为半径和角度的方程式: x = r*Cos(Q) y = r*Sin(Q) r= sqrt(x*x + y*y) Q = tan^-1(y/x) 我的问题是我不记得 Objec
我正在尝试编写一个 if 语句,表示如果 block1 的位置超过某个点,则这种情况会发生在 block3 上。但是,当我尝试使用 >= 进行比较时,出现错误:“无法使用列表类型的参数调用 >= (@
我有一个带有 CGPoint 的 NSMutableArray。当我尝试将对象添加到我的 CGPoint 变量时,我看到了这个错误: Assigning to 'CGPoint' (aka 'stru
我遇到了快速构建错误。 func pathRefFromText() -> CGPathRef { let attributed : NSAttributedString = self
我有这个属性: @property (nonatomic) NSArray *vertices; 其中顶点的类型为CGPoint。 我知道 swift 有一些方便的语言功能,例如 NS_SWIFT_N
你好,对于基于导航的应用程序,我需要从 MKMapView 的坐标或 MKMapPoint 获取 CGPoint。我想在这些点之间画一条线,而不是折线。 我对 MKPolyLine 和其他自定义折线了
我正在使用 Firebase,并尝试将 [CGPoint] 数据库用于实时游戏。我尝试将结构类型更改为 [NSValue] 因为至少它符合 AnyObject (请参阅下面的代码),但现在我收到运行时
有没有简单的方法来做到这一点。 我有一个 CGPoint pointA (10, 10) 和另一个 CGPoint pointB (15, 8)。我需要得到一个 CGPoint,它与连接 A 和 B
如何获取tableView中选定的sectionIndexTitle的点(CGPoint)?我没有找到任何方法来实现这一点。 - (NSInteger)tableView:(UITableView *
我的类的界面部分有 CGPoint @interface MyClass () { CGPoint point; } 在代码中我尝试为其设置值 point = CGPointMake(1, 3
我有一个 CGPoints 数组,我想找到那些构建形状的点。请看附图: 红色圆圈只是标记我的点数。 如何找到带问号的区域? 谢谢。 最佳答案 您必须从第一条线段开始并检查是否有交点。显然,如果前两条线
我正在用下面的线创建圆弧 func drawSomething(_ context: CGContext, rect: CGRect) { context.saveGState() l
我是一名优秀的程序员,十分优秀!