【问题标题】:Simple 5 seconds progress bar view?简单的 5 秒进度条视图?
【发布时间】:2014-03-22 04:06:25
【问题描述】:

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

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

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

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

【问题讨论】:

  • 我只是建议你使用 UIActivityIndi​​cator 来代替它。

标签: ios objective-c progress-bar uiprogressview


【解决方案1】:

让我们以这种方式实现 5 分钟的进度视图,

在.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;
    }
}

谢谢!

【讨论】:

    【解决方案2】:

    这应该让你开始:

    @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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2021-12-19
      • 1970-01-01
      • 2012-08-21
      • 2013-05-10
      • 2015-11-24
      相关资源
      最近更新 更多