(3) 计时器NSTimer

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;

- (NSDate *)fireDate; 获得计时器开始时间

- (void)invalidate; 关闭计时器

NSTimer

//timerWithTimeInterval创建的timer需要添加到主线程中才能执行

self.timer = [NSTimer timerWithTimeInterval:1.5 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

 //scheduledTimerWithTimeInterval方法创建的无需添加到主线程即可执行

self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self 
selector:@selector(nextImage) userInfo:nil repeats:YES];

 //停止定时器

[self.timer invalidate];

self.timer = nil;

iOS-NSTimer计时器的更多相关文章

  1. iOS开发--计时器-NSTimer与CADisplayLink

    如果程序要让某个方法重复执行,可以借助定时器来完成.CADisplayLink是一个能让我们以和屏幕刷新率相同的频率将内容画到屏幕上的定时器,NSTimer的精确度低了点,比如NSTimer的触发时间 ...

  2. iOS NSTimer使用详解 开启、关闭、移除

    定时器定时器详解ios定时器关闭定时器NSTimer 一,要使用一个定时器首先要定义一个定时器: @property (strong, nonatomic) NSTimer *myTimer;//定时 ...

  3. 【转】IOS NSTimer 定时器用法总结

    原文网址:http://my.oschina.net/u/2340880/blog/398598 NSTimer在IOS开发中会经常用到,尤其是小型游戏,然而对于初学者时常会注意不到其中的内存释放问题 ...

  4. IOS NSTimer 定时器用法总结

    NSTimer在IOS开发中会经常用到,尤其是小型游戏,然而对于初学者时常会注意不到其中的内存释放问题,将其基本用法总结如下: 一.初始化方法:有五种初始化方法,分别是 + (NSTimer *)ti ...

  5. ios - NSTimer中target的self是强引用问题

    当控制器ViewController跳转进入控制器OneViewController中的时候开启定时器,让定时器每隔一段时间打印一次,当OneViewController dismiss的时候,控制器 ...

  6. IOS NSTimer和CADisplayLink的用法

    IOS--NSTimer和CADisplayLink的用法 NSTimer初始化器接受调用方法逻辑之间的间隔作为它的其中一个参数,预设一秒执行30次.CADisplayLink默认每秒运行60次,通过 ...

  7. iOS NSTimer

    示例: //创建 scrollTimer =[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selecto ...

  8. ios NSTimer的强引用问题

    在一个controller中,使用 NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest ...

  9. iOS: NSTimer使用小记

    目录 1. NSRunLoopCommonModes和Timer 2. NSThread和Timer 3. GCD中的Timer 返回目录 1. NSRunLoopCommonModes和Timer ...

  10. [置顶] ios 时间定时器 NSTimer应用demo

    原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917 demo功能:ios NSTimer应用demo .ipho ...

随机推荐

  1. IAR平台移植TI OSAL到STC8A8K64S4A12单片机中

    玩过TI 的ZigBee或者BLE的人,都会接触到OSAL.OSAL是什么?OSAL英文全称:operating system abstraction layer(操作系统抽象层).基于OSAL的调度 ...

  2. 39、扩展原理-BeanFactoryPostProcessor

    39.扩展原理-BeanFactoryPostProcessor BeanPostProcessor:bean后置处理器,bean创建对象初始化前后进行拦截工作的 BeanFactoryPostPro ...

  3. Oracle 中MERGE语句的用法

    原文章出处(http://blog.csdn.net/lichkui/article/details/4306299) MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语 ...

  4. tmux-cheatsheet

    http://tmuxcheatsheet.com/ http://louiszhai.github.io/2017/09/30/tmux/ 滚屏 开启 Ctrl-b pageup/pagedown ...

  5. 搭建自己的博客(十七):添加每日阅读量并使用highcharts通过图表显示

    之前写了单篇博客的阅读量统计,今天添加了博客总阅读量统计,并且使用highcharts图表显示. 1.变化的部分

  6. 通过ResultSet获取到rs的记录数的几种方法

    方法一:利用ResultSet的getRow方法来获得ResultSet的总行数 ResultSet rs = ps.executeQuery(sql); rs.last(); //移到最后一行 in ...

  7. manjaro xfce4 使用super+D快捷键显示桌面(以及使用super+方向键调整窗口)设置无效

    xfce4 有两个地方设置快捷键:Keyboard -> application shortcuts 和 window manager -> keyboard. window manage ...

  8. java 标准日期格式

    public static void main(String[] argv) { // 使用默认时区和语言环境获得一个日历 Calendar cale = Calendar.getInstance() ...

  9. codeforces#1248D2. The World Is Just a Programming Task(括号匹配转化为折线处理)

    题目链接: http://codeforces.com/contest/1248/problem/D2 题意: 可以执行一次字符交换的操作 使得操作后的字符串,循环移位并且成功匹配的方案最多 输出最多 ...

  10. android studio3.4打jar包

    第一步在build.gradle文件里的android{}里面加入下面内容 //生成jar包 task makeJar(type:Copy) { delete 'build/outputs/netwo ...