我試圖創建一個SplashView,它在後臺顯示Default.png和前面的UIProgressBar。但啓動畫面沒有被更新...iPhone - 啓動屏幕進度條
在我的視圖控制器中我首先加載初始化視圖與參數多少個步驟我的初始化,然後我通過NSTimer啓動第二個線程,並在每個初始化步驟後,我告訴SplashView顯示新的進度值。
理論上看起來不錯,但運行此應用程序時進度條並未更新(啓動畫面的方法接收到值,我可以在日誌中看到它)。我也嘗試加入睡眠(10000);在兩者之間給視圖更新一點時間,而不是使用我直接在視圖上繪製的進度條,並調用[self setNeedsDisplay];但都沒有工作:/
我在做什麼錯?
感謝您的幫助!
湯姆
下面是一些代碼:
SPLASHSCREEN: - (id)initWithFrame:(CGRect)frame withStepCount:(int)stepCount { if (self = [super initWithFrame:frame]) { // Initialization code background = [[UIImageView alloc] initWithFrame: [self bounds]]; [background setImage: [UIImage imageWithContentsOfFile: [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"Default.png"]]]; [self addSubview: background]; progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; [progressView setFrame:CGRectMake(60.0f, 222.0f, 200.0f, 20.0f)]; [progressView setProgress: 0.0f]; stepValue = 1.0f/(float)stepCount; [self addSubview:progressView]; } return self; } - (void)tick { value += stepValue; [progressView setProgress: value]; } VIEWCONTROLLER: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { splashView = [[SplashView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f) withStepCount:9]; [self setView: splashView]; NSTimer* delayTimer; delayTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(finishInitialization) userInfo:nil repeats:NO]; } return self; } - (void)finishInitialization { // do some stuff, like allocation, opening a db, creating views, heavy stuff... [splashView tick]; // this should update the progress bar... // do some stuff, like allocation, opening a db, creating views, heavy stuff... [splashView tick]; // this should update the progress bar... // init done... set the right view and release the SplashView }
好吧,我將創建一個UIView,添加'UIImageView',然後添加默認值。png,然後我將添加一個'UIActivityIndicator'並將它顯示在'mainWindow'之上。我的問題是在哪個事件中我應該關閉啓動畫面? – sharon 2012-02-13 14:59:16