MTTimer 0.0.1

MTTimer 0.0.1

测试已测试
语种语言 Obj-CObjective C
许可 MIT
发布日期最新发布2014年12月

Adam Kirk 维护。



MTTimer 0.0.1

  • 作者:
  • Adam Kirk

一个 Objective-C 计时器,限制触发时间范围。如果它在 min 之前被取消,它将等待 min。如果它在 max 之后被取消,将在 max 时触发。

FirehoseMysterious Trousers 开发。

安装

示例

@implementation FMRootWindowView {
    MTTimer *_durationTimer;
}

#pragma mark - Public

- (void)displayLoadingWithMessage:(NSString *)message
{
    ...

    // It's kind of jolting to see a loading message pop up and disappear in 
    // just a few miliseconds, in the case of a request that loads very quickly, 
    // so we constrain the timer to not fire until at least 2 seconds, even if
    // `done` is called before that.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 untilPerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displaySuccessWithMessage:(NSString *)errorMessage
{
    ...

    // We want a the success message to show for at least 2 seconds, but we 
    // don't want it showing more than 4.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 atMost:4 beforePerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displayErrorWithMessage:(NSString *)errorMessage
{
    ...

    // We want a the error message to show for at least 30 seconds, to make 
    // sure the user sees it.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:30 atMost:35 beforePerformingBlock:^{
        [self animateUp];
    }];

    ...
}

- (void)dismissStatus
{
    // This is called whenever your external operation is complete. If `done` is calle BEFORE
    // the min seconds has been reached, the completion block will not fire until min is reached.
    // If you call this AFTER max, the completion block will have already fired when max was reached.
    [_durationTimer done];
}

@end

贡献

请在提交 pull request 之前更新和运行测试。谢谢。

作者

Adam Kirk (@atomkirk)