码迷,mamicode.com
首页 > 其他好文 > 详细

定时器

时间:2017-09-22 22:34:50      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:定时器   hup   for   style   ida   targe   uibutton   orange   repeat   

 

 

 

 

 

- (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);
    
}

 

定时器

标签:定时器   hup   for   style   ida   targe   uibutton   orange   repeat   

原文地址:http://www.cnblogs.com/vector11248/p/7577100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!