我用下面的代碼來畫虛線如何讓虛線動
// get the current CGContextRef for the view
CGContextRef currentContext =
(CGContextRef)[[NSGraphicsContext currentContext]
graphicsPort];
// grab some useful view size numbers
NSRect bounds = [self bounds];
float width = NSWidth(bounds);
float height = NSHeight(bounds);
float originX = NSMinX(bounds);
float originY = NSMinY(bounds);
float maxX = NSMaxX(bounds);
float maxY = NSMaxY(bounds);
float middleX = NSMidX(bounds);
float middleY = NSMidY(bounds);
CGContextSetLineWidth(currentContext, 10.0);
float dashPhase = 0.0;
float dashLengths[] = { 20, 30, 40, 30, 20, 10 };
CGContextSetLineDash(currentContext,
dashPhase, dashLengths,
sizeof(dashLengths)/sizeof(float));
CGContextMoveToPoint(currentContext,
originX + 10, middleY);
CGContextAddLineToPoint(currentContext,
maxX - 10, middleY);
CGContextStrokePath(currentContext);
它是靜態的。
但我更喜歡做活動的虛線和間隙
移動由右至左和圈
這可能嗎?
進一步改善的情況:
虛線和間隙順時針移動自動
歡迎任何評論
真棒問題。我希望早晚實現到我的代碼中的東西只是不知道如何。 +1 –