0
如果我需要將兩個形狀相加或相減並將其作爲一個整體進行動畫化,那麼最簡單的方法是什麼?例如,如果我從一個更大的圓圈中減去一個更小的圓圈,我會得到一個圓環。添加和減去形狀
如果我然後需要動畫這個實體,並動畫這些類型的實體(甜甜圈或其他)許多會在iPad上沉重嗎?
我需要一個方向來看看。
謝謝!
如果我需要將兩個形狀相加或相減並將其作爲一個整體進行動畫化,那麼最簡單的方法是什麼?例如,如果我從一個更大的圓圈中減去一個更小的圓圈,我會得到一個圓環。添加和減去形狀
如果我然後需要動畫這個實體,並動畫這些類型的實體(甜甜圈或其他)許多會在iPad上沉重嗎?
我需要一個方向來看看。
謝謝!
您的文章標有關鍵字「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()
看到其他的方式來夾形狀。
嗨,謝謝。這是我知道的方法,我想知道是否有更好和更有效的方法,或者這種方法足夠滿足我的需求。 –