我尝试创建一个SplashView,它在背景中显示Default.png,前面有一个UIProgressBar。但是启动画面没有更新...
在我的视图控制器中,我首先加载带有参数的闪屏视图,该参数表示我的初始化步骤数量,然后我通过NSTimer启动第二个线程,并在每个初始化步骤之后告诉SplashView显示新的进度值。
理论上看起来很好,但是运行此应用程序时,进度条不会更新(闪屏屏幕的方法接收到值,我可以在日志中看到)。我还尝试在其中添加usleep(10000);以给视图更新一些时间,而且也没有使用进度条,而是直接在视图上绘制并调用[self setNeedsDisplay];但都没有成功 :/
我做错了什么?
感谢您的帮助!
Tom
下面是一些代码:
SPLASHSCREEN: - (id)initWithFrame:(CGRect)frame withStepCount:(int)stepCount { if (self = [super initWithFrame:frame]) { // 初始化代码
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 { // 做一些事情,比如分配,打开数据库,创建视图,重型工作... [splashView tick]; // 这应该更新进度条...
// 做一些事情,比如分配,打开数据库,创建视图,重型工作... [splashView tick]; // 这应该更新进度条...
// 初始化完成...设置正确的视图并释放SplashView
在我的视图控制器中,我首先加载带有参数的闪屏视图,该参数表示我的初始化步骤数量,然后我通过NSTimer启动第二个线程,并在每个初始化步骤之后告诉SplashView显示新的进度值。
理论上看起来很好,但是运行此应用程序时,进度条不会更新(闪屏屏幕的方法接收到值,我可以在日志中看到)。我还尝试在其中添加usleep(10000);以给视图更新一些时间,而且也没有使用进度条,而是直接在视图上绘制并调用[self setNeedsDisplay];但都没有成功 :/
我做错了什么?
感谢您的帮助!
Tom
下面是一些代码:
SPLASHSCREEN: - (id)initWithFrame:(CGRect)frame withStepCount:(int)stepCount { if (self = [super initWithFrame:frame]) { // 初始化代码
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 { // 做一些事情,比如分配,打开数据库,创建视图,重型工作... [splashView tick]; // 这应该更新进度条...
// 做一些事情,比如分配,打开数据库,创建视图,重型工作... [splashView tick]; // 这应该更新进度条...
// 初始化完成...设置正确的视图并释放SplashView