2013-10-22 96 views
0

如果我需要将两个形状相加或相减并将其作为一个整体进行动画化,那么最简单的方法是什么?例如,如果我从一个更大的圆圈中减去一个更小的圆圈,我会得到一个圆环。添加和减去形状

如果我然后需要动画这个实体,并动画这些类型的实体(甜甜圈或其他)许多会在iPad上沉重吗?

我需要一个方向来看看。

谢谢!

回答

0

您的文章标有关键字“Core-Graphics”,所以我认为这就是您想要使用的。要添加形状,只需将两个或更多形状一起绘制。我建议遵循以下模式:保存图形状态,绘制连接的形状,并恢复绘制下一组形状的图形状态。就像这样:

// 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()看到其他的方式来夹形状。

+0

嗨,谢谢。这是我知道的方法,我想知道是否有更好和更有效的方法,或者这种方法足够满足我的需求。 –