我试图创建一个 SplashView,它在后台显示 Default.png,在前面显示一个 UIProgressBar。但是启动画面没有更新...
在我的视图控制器中,我首先加载带有参数的初始视图,我的初始化有多少步,然后我通过 NSTimer 启动第二个线程,在每个初始化步骤之后,我告诉 SplashView 显示新的进度值。
理论上一切看起来都不错,但是在运行这个应用程序时,进度条没有被更新(启动屏幕的方法接收值,我可以在日志中看到它)。我还尝试添加 usleep(10000); 在两者之间给视图更新一点时间,而不是使用进度条,我直接在视图上绘制并调用 [self setNeedsDisplay];但一切都没有奏效:/
我究竟做错了什么?
谢谢你的帮助!
汤姆
这是一些代码:
启动画面:
- (id)initWithFrame:(CGRect)frame withStepCount:(int)stepCount {
if (self = [super initWithFrame:frame]) {
// 初始化代码
背景 = [[UIImageView alloc] initWithFrame: [self bounds]];
[背景setImage: [UIImage imageWithContentsOfFile: [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"Default.png"]]];
[自我添加子视图:背景];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(60.0f, 222.0f, 200.0f, 20.0f)];
[progressView 设置进度:0.0f];
stepValue = 1.0f / (float)stepCount;
[自我 addSubview:progressView];
}
回归自我;
}
-(无效)勾选{
值 += 步值;
[progressView 设置进度:值];
}
浏览器:
- (id)initWithNibName:(NSString *)nibNameOrNil 包:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
splashView = [[SplashView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f) withStepCount:9];
[自我setView:splashView];
NSTimer* 延迟定时器;
delayTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 目标:自我选择器:@selector(finishInitialization) userInfo:nil repeats:NO];
}
回归自我;
}
- (void)finishInitialization {
// 做一些事情,比如分配、打开数据库、创建视图、繁重的事情......
[splashView 勾选]; // 这应该更新进度条...
// 做一些事情,比如分配、打开数据库、创建视图、繁重的事情......
[splashView 勾选]; // 这应该更新进度条...
// 初始化完成...设置正确的视图并释放 SplashView
}