定时器

Posted vector11248

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了定时器相关的知识,希望对你有一定的参考价值。

 

 

 

 

 

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   // self.view.backgroundColor = [UIColor orangeColor];

    UIButton* btnStart = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnStart.frame = CGRectMake(100, 100, 50, 50);
    [btnStart setTitle:@"start" forState:UIControlStateNormal];
    [btnStart addTarget:self action:@selector(pressStart) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btnStart];
    
    
    UIButton* btnStop = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnStop.frame = CGRectMake(100, 200, 50, 50);
    [btnStop setTitle:@"stop" forState:UIControlStateNormal];
    [btnStop addTarget:self action:@selector(pressStop) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btnStop];
    
    UIView* view = [[UIView alloc]init];
    view.frame = CGRectMake(0,0,80,80);
    view.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:view];
    view.tag = 101;
    
    
    
    

}

-(void) pressStart
{
    //NSLog(<#NSString * _Nonnull format, ...#>);
    _timerView =  [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateTimer:) userInfo:@"Li" repeats:YES];
    
    
}
-(void) pressStop
{
    if(_timerView!=nil){
        [_timerView invalidate];
    }
    
}
-(void) updateTimer:(NSTimer*) timer
{
    NSLog(@"Test name =%@",timer.userInfo);
    UIView *view = [self.view viewWithTag:101];
    view.frame = CGRectMake(view.frame.origin.x+1, view.frame.origin.y+1, 50, 50);
    
}

 

以上是关于定时器的主要内容,如果未能解决你的问题,请参考以下文章

前端面试题之手写promise

HTML代码片段

HTML代码片段

CPNtools协议建模安全分析---实例变迁标记

分享几个实用的代码片段(附代码例子)

分享几个实用的代码片段(附代码例子)