简体   繁体   English

如何慢慢填充NSProgressIndicator(进度条)从0到100?

[英]How to slowly fill the NSProgressIndicator (Progress Bar) from 0 to 100?

Task : Take Progress bar (NSProgressIndicator) from 0 to 100 smoothly. 任务 :顺利进行从0到100的进度条(NSProgressIndicator)。

Problem : Progress bar is getting 0 to 100 but not smoothly. 问题 :进度条从0到100但不顺利。

What I have done as yet: 我到目前为止所做的事情:

    // scan click on which the prgress should start
-(void)ScanNowClick:(id)sender
{
        // setting initial value of progress bar
        [progressbar setDoubleValue:0];
        // starting timer
        [NSTimer scheduledTimerWithTimeInterval:0.5
                                         target:self
                                       selector:@selector(callAfter10sec:)
                                       userInfo:nil
                                        repeats:YES];  
}

// timer that will update progress bar
-(void)callAfter10sec:(NSTimer *)time {

    double value = [progressbar doubleValue]+10;

    [[progressbar animator] setDoubleValue:value];

    if(value >= 100)
    {
       [time invalidate];
    }
}

/// layer is also set ///层也设置了

在此输入图像描述

You should use CADisplayLink and not NSTimer when dealing with UI related updates. 在处理与UI相关的更新时,您应该使用CADisplayLink而不是NSTimer

The link is called 60 times per second (per the refresh rate of the screen) 该链接每秒调用60次(按屏幕刷新率)

In the callback you should calculate the proportion to advance the view 在回调中,您应该计算推进视图的比例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM