我试图创建一个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