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