如果我需要一起添加或减去两个形状并将其作为一个整体进行动画处理,那么最简单的方法是什么?例如,如果我从一个较大的圆圈中减去一个较小的圆圈,我会得到一个甜甜圈。
如果我需要为这个实体制作动画,并且还要为许多此类实体(甜甜圈或其他)制作动画,它在 iPad 上会很重吗?
我需要一个方向来研究。
谢谢!
如果我需要一起添加或减去两个形状并将其作为一个整体进行动画处理,那么最简单的方法是什么?例如,如果我从一个较大的圆圈中减去一个较小的圆圈,我会得到一个甜甜圈。
如果我需要为这个实体制作动画,并且还要为许多此类实体(甜甜圈或其他)制作动画,它在 iPad 上会很重吗?
我需要一个方向来研究。
谢谢!
您的帖子标有关键字“Core-Graphics”,所以我认为这就是您想要使用的。要添加形状,您只需将 2 个或更多您想要的形状一起绘制。我建议遵循保存图形状态、绘制连接的形状以及恢复图形状态以绘制下一组形状的模式。像这样:
// Save the state
CGContextSaveGState (ctx);
// Do your drawing
CGContextBeginPath (ctx);
CGContextAddRect (ctx, rect);
CGContextAddEllipseInRect (ctx, ellipseRect); // Or whatever
CGContextClosePath (ctx);
CGContextFillPath (ctx);
// Restore the state
CGContextRestoreGState (ctx);
要减去形状,您可以使用剪切路径:
// This is the path you want to draw within
CGContextBeginPath (ctx);
CGContextAddRect (ctx);
CGContextClosePath (ctx);
CGContextClip (ctx);
// Now draw the shape you want constrained within the above path
CGContextBeginPath (ctx);
CGContextAddEllipseInRect (ctx, ellipseRect);
CGContextClosePath (ctx);
CGContextFillPath (ctx); // This will fill everything in the path that is also within the clipping path, and nothing that is outside of the clipping path
另请参阅CGContextEOClip()
其他剪辑形状的方法。