首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >简单的5秒进度条视图?

简单的5秒进度条视图?
EN

Stack Overflow用户
提问于 2014-03-22 12:06:26
回答 2查看 2.2K关注 0票数 0

我是编程新手,目前正在开发一个指南/参考应用程序(我的第一个应用程序)。

我一直在使用接口构建器来完成大部分工作。我知道我很快就需要使用代码,但现在我喜欢使用IB学习。

这是我的问题:我有一个有很多高清图片的视图,它需要4-5秒的加载时间,直到我可以平滑地滚动页面。我想添加一个进度视图栏(在UITableView和导航栏之间),它显示5秒的进度,以便让用户知道它仍在加载(我知道活动指示器,但进度视图栏看起来更好,似乎更容易使用)。

有人可以指导我完成所有的步骤,以便使进度视图栏充当5秒计时器吗?

EN

回答 2

Stack Overflow用户

发布于 2014-03-22 12:28:31

让我们以这种方式实现5分钟progressView,

在.h文件中,

代码语言:javascript
运行
复制
NSTimer * timer;

UIProgressView * progView;

float duration;

在.m文件中

代码语言:javascript
运行
复制
- (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;
    }
}

谢谢!

票数 2
EN

Stack Overflow用户

发布于 2014-03-22 12:27:43

这应该可以让你开始:

代码语言:javascript
运行
复制
@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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22573321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档