我对 Quartz 2D 还很陌生。
想象以下场景:
你有一个圆形的迷你地图视图。我正在地图顶部绘制三角形(弧线现在并不重要)。这个形状代表可见区域。
当用户改变方向时,我需要让三角形沿着迷你地图旋转。
目前这是绘制路径的方式:
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGPath visibleAreaPath = CGPathCreateMutable();
CGPathMoveToPoint(visibleAreaPath, &transform, miniMapCenter.x, miniMapCenter.y);
CGPathAddLineToPoint(visibleAreaPath, &transform, 18.0, 8.0);
CGPathAddLineToPoint(visibleAreaPath, &transform, 66.0, 8.0);
CGPathCloseSubpath(visibleAreaPath);
然后我使用 CAShapeLayer 绘制路径,如下所示:
CALayer *rootLayer = [visibleAreaView layer];
visibleAreaShape = [CAShapeLayer layer];
[visibleAreaShape setFillColor:[UIColor colorWithHue:0.584 saturation:0.8 brightness:0.9 alpha:0.6].CGColor];
[visibleAreaShape setFillRule:kCAFillRuleNonZero];
[visibleAreaShape setAnchorPoint:CGPointMake(0.5, 0.5)];
[rootLayer addSublayer:visibleAreaShape];
[visibleAreaShape setPath:visibleAreaPath];
路径正在旋转,但不是基于给定的原点。请记住,设置图层的锚点对我没有帮助,因为我想要的是旋转路径(最终我什至不需要显示它,因为我将使用它来确定哪些点在 mini 上可见地图)。
关于如何做到这一点的任何想法?谢谢你。