1

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

4

2 回答 2

4

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

截屏

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

[progressIndicatorOutlet setIndeterminate:NO];

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


确定 NSProgressIndicator动画:

只需像这样设置和更改值非常简单:

[progressIndicatorOutlet setDoubleValue:10];

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


NS定时器:

简单的计时器示例:

//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];

不要忘记添加我在这样的评论中提到的类:

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

}
于 2012-05-20T21:08:41.010 回答
0

希望能帮助到你。

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

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];
}
于 2015-10-02T11:24:36.447 回答