CADisplayLink类似NSTimer是一个定时器,只不过是一秒会调用60次指定的方法

使用方法:

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, assign) int count; @end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 创建CADisplayLink
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkEvent)]; [self performSelector:@selector(eventOne) withObject:nil afterDelay:]; // 一秒后销毁
[self performSelector:@selector(eventTwo) withObject:nil afterDelay:];
} - (void)eventTwo
{
[self.displayLink invalidate];
} - (void)eventOne
{
// 添加到循环圈(开始执行)
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
} - (void)displayLinkEvent
{
self.count++;
NSLog(@"%i",self.count);
} @end

其中,displayLinkEvent方法在一秒内被调用了60次。

最新文章

  1. ASP.NET获取真正的客户端IP地址的6种方法
  2. win 10 常见问题
  3. uC/OS-II内核的服务文件
  4. ASP.NET MVC的Ajax.ActionLink 的HttpMethod="Get" 一个重复请求的BUG
  5. LINUX下的tty,console与串口分析
  6. Java学习笔记(二):String
  7. IOS 应用程序启动加载过程(从点击图标到界面显示)
  8. javaweb一周总结(菜鸟)
  9. [模式识别].(希腊)西奥多里蒂斯<第四版>笔记8它__模板匹配
  10. swift3.0 对UITextField()输入框输入的内容进行监控
  11. Servlet知识点大纲
  12. 移动前端的html5 head 头标签
  13. SkyReach 团队团队展示
  14. 安装VC6.0安装步骤及心得体会
  15. dede织梦手机站m文件夹功能基础详解
  16. innobackupex 远程备份
  17. c++11 线程池学习笔记 (一) 任务队列
  18. Python -- queue队列模块
  19. Java国际化号码验证方法,国内手机号正则表达式
  20. DevExpress v18.1新版亮点——Office File API篇

热门文章

  1. 你不知道的JavaScript(作用域和闭包)
  2. 转:微博CacheService架构浅析
  3. SQL Server T-SQL高级查询1
  4. intel集成显卡linux驱动安装
  5. HDU 4421 Bit Magic(奇葩式解法)
  6. 【模拟】HDU 5752 Sqrt Bo
  7. Xamarin Crack
  8. 《算法实战策略》-chaper19-队列、栈和双端队列
  9. View inflate方法和LayoutInflater inflate方法的区别详解
  10. 解决Item控件抢占焦点