标签:style blog io color ar 使用 sp for strong
- (void)paint:(NSTimer *)paramTimer{ NSLog(@"Painting"); } - (void)startPainting{ self.paintingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(paint:) userInfo:nil repeats:YES]; } - (void)stopPainting{ if (self.paintingTimer != nil) { [self.paintingTimer invalidate];//invalidate[?n‘væl?de?t]使无效无价值 } } - (void)applicationWillResignActive:(UIApplication *)application { [self stopPainting]; } - (void)applicationDidBecomeActive:(UIApplication *)application { [self startPainting]; }
interval等待秒数 target接收事件的目标对象 selector目标对象里响应事件的方法 userInfo可传递信息,包含在传递的计时器中 repeat是否重复
2.
- (void)startPainting{ //2. /* Here is the selector that we want to call */ SEL selectorToCall = @selector(paint:); //转成方法签名?Signature签名 instance实例 NSMethodSignature *methodSignature = [[self class]instanceMethodSignatureForSelector:selectorToCall]; //?? NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; [invocation setTarget:self]; [invocation setSelector:selectorToCall]; /* start a scheduled timer now*/ self.paintingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 invocation:invocation repeats:YES]; }
- (void) startPainting{ self.paintingTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(paint:) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop]addTimer:self.paintingTimer forMode:NSDefaultRunLoopMode]; }
标签:style blog io color ar 使用 sp for strong
原文地址:http://www.cnblogs.com/safiri/p/4080743.html