我是编程新手,目前正在开发一个指南/参考应用程序(我的第一个应用程序)。
我一直在使用接口构建器来完成大部分工作。我知道我很快就需要使用代码,但现在我喜欢使用IB学习。
这是我的问题:我有一个有很多高清图片的视图,它需要4-5秒的加载时间,直到我可以平滑地滚动页面。我想添加一个进度视图栏(在UITableView
和导航栏之间),它显示5秒的进度,以便让用户知道它仍在加载(我知道活动指示器,但进度视图栏看起来更好,似乎更容易使用)。
有人可以指导我完成所有的步骤,以便使进度视图栏充当5秒计时器吗?
发布于 2014-03-22 12:28:31
让我们以这种方式实现5分钟progressView,
在.h文件中,
NSTimer * timer;
UIProgressView * progView;
float duration;
在.m文件中
- (void)viewDidLoad
{
[super viewDidLoad];
progView = [[UIProgressView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 10.0)];
[self.view addSubview:progView];
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];;
}
-(void)updateProgress
{
duration += 0.1;
progView.progress = (duration/5.0); // here 5.0 indicates your required time duration
if (progView.progress == 1)
{
[timer invalidate];
timer = nil;
}
}
谢谢!
发布于 2014-03-22 12:27:43
这应该可以让你开始:
@property (nonatomic, strong) NSTimer *progressTimer;
@property (nonatomic, assign) CGFloat progress;
@property (nonatomic, strong) UIProgressView *progressView;
- (void)yourMethod
{
if (!self.progressView)
{
self.progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 64, 320, 2)];
self.progressView.progressTintColor = [UIColor greenColor];
[self.navigationController.navigationBar.superview insertSubview:self.progressView belowSubview:self.navigationController.navigationBar];
}
else
{
self.progressView.hidden = NO;
}
self.progressTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateProgressView) userInfo:nil repeats:YES];
NSTimer *stopProgressTimer = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(stopProgressView) userInfo:nil repeats:NO];
[stopProgressTimer fire];
}
- (void)stopProgressView
{
[self.progressTimer invalidate];
self.progress = 0.0f;
self.progressView.hidden = YES;
self.progressView.progress = 0.0f;
}
- (void)updateProgressView
{
self.progress = (self.progress + 0.1f) / 5;
self.progressView.progress = self.progress;
}
https://stackoverflow.com/questions/22573321
复制相似问题