[英]Creating animated progress bar in iOS
我正在嘗試為iPad應用程序制作自定義動畫條形圖(即,條形高度在激活時會增加到設置的水平)。 我對iOS開發非常陌生,我只想獲得有關如何完成此任務的反饋。
我試圖玩弄在回答這個條目,我想知道,如果它是正確的,我是從這個點開始。
如果只需要一個實心條,則可以創建所需大小和位置的UIView,設置其背景色,然后將其添加到視圖中。 這是不錯的編碼,使用UIView繪制實心矩形也不會感到羞恥。 :]
對於更復雜的圖形,您可能想要創建UIView的自定義子類,並覆蓋其drawRect消息以進行一些自定義繪制。 例如:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0, 1.0); // opaque yellow
CGContextMoveToPoint(context, x1, y1); // for suitable definition of x1,y1, etc
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);
}
或您可能想做的任何其他CGContext *繪圖類型(例如餅圖,折線圖等)。
要通過添加具有背景色的UIView為創建的條設置動畫 ,請在動畫開始時粘貼以下內容:
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
self.startTime = [NSDate date];
然后添加以下消息(注意:條形將向上增長)。
- (void) onTimer:(NSTimer*)firedTimer
{
float time = [self.startTime timeIntervalSinceNow] * -1;
if (time>kMaxTime)
{
[timer invalidate];
timer = nil;
time = kMaxTime;
}
int size = time * kPixelsPerSecond;
myBar.frame = CGRectMake(x, y - size, width, size);
}
關於該鏈接的idk,但是您可以從此處http://preloaders.net/生成它們,這應該為您制作自己的書奠定良好的基礎
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.