【问题标题】:linking a NSTimer to a NSProgressIndicator将 NSTimer 链接到 NSProgressIndicator
【发布时间】:2012-05-20 17:46:13
【问题描述】:

我需要创建一个NSTimer,它会告诉另一个类在 10 秒内触发,我还想用它来为确定的NSProgressIndicator 设置动画。我还需要知道如何将我的不确定进度指示器更改为确定。我能够找到关于此的 Apple 文档,但是更深入的解释会有所帮助。

【问题讨论】:

    标签: cocoa nstimer nsprogressindicator


    【解决方案1】:

    从不确定到确定NSProgressIndicator 你可以在 IB 中更改。选择您的 progressIndicator 并转到属性检查器并取消选中 Indeterminate 复选框,如下所示:

    或者它可以通过编程方式完成:

    [progressIndicatorOutlet setIndeterminate:NO];
    

    注意:progressIndicatorOutlet 是您的NSProgressIndicator 出口,所以不要忘记IBOutlet 它。


    确定 NSProgressIndicator 动画:

    这很简单,只需像这样设置和更改值:

    [progressIndicatorOutlet setDoubleValue:10];
    

    注意:progressIndicatorOutlet 是您的NSProgressIndicator 出口,所以不要忘记IBOutlet 它。


    NSTimer:

    简单的计时器示例:

    //Place this where You want to call class after 10 sec. (for example: when button pressed)
    //It will call class with name callAfter10sec after 10 sec. Place in there what You need to do. 
    
    [NSTimer scheduledTimerWithTimeInterval:10.0
                                     target:self
                                   selector:@selector(callAfter10sec:)
                                   userInfo:nil
                                    repeats:YES];
    

    不要忘记添加我在 cmets 中提到的类:

    -(void)callAfter10sec:(NSTimer *)time {
        // Do what You want here
    
    }
    

    【讨论】:

    • 感谢分配,这真的很有帮助。
    【解决方案2】:

    希望对你有帮助。

    使用以下方式我们可以达到预期的效果

    NSInteger progressValue;
    NSTimer *timerObject;
    
    progressValue = progressMaxValue;
    
    timerObject = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(incrementProgressBar) userInfo:nil repeats:YES];
    
    [timerObject fire];
    [self.progressBar setMinValue:progressMinValue]; 
    [self.progressBar setMaxValue:progressMaxValue];
    [self.progressBar setDoubleValue:progressValue];
    
    - (void)incrementProgressBar {
        // Increment the progress bar value by 1
        [self.progressBar incrementBy:1.0];
        progressValue--;
        [self.progressBar setDoubleValue:progressValue];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多