IOS 添加定时器(NSTimer)
定时器
CADisplayLink:时间间隔比较小(使用时间频率高)的时候用(适合小游戏中开发)
NSTimer:时间间隔比较大的时候调用(适合图片轮放的时候用)
//声明定时器
@property (nonatomic,strong) NSTimer *timer;
- /**
- * 添加定时器
- */
- - (void)addTimer
- {
- self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
- //NSRunLoop可以优先级处理些定时器(线程优先)
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
- }
- /**
- * 移除定时器
- */
- - (void)removeTimer
- {
- [self.timer invalidate];//设置定时器无效
- self.timer = nil;
- }
调用代理时 定时器 事例:
#pragma mark -代理方法
- /**
- 当scrollView正在滚动就会调用
- */
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
- //根据scrollView的滚动位置决定pageControl显示第几页
- CGFloat scrollW=self.scrollView.frame.size.width;
- int page=(scrollView.contentOffset.x+scrollW*0.5)/scrollW;
- self.pageControl.currentPage=page;
- }
- /**
- 开始拖拽的时候调用
- */
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- //停止定时器(一旦定时器停止了,就不能再使用)
- [self removeTimer];
- }
- /**停止拖拽的时候调用*/
- -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
- {
- //开启定时器
- [self addTimer];
- }
IOS 添加定时器(NSTimer)的更多相关文章
- [置顶] ios 时间定时器 NSTimer应用demo
原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917 demo功能:ios NSTimer应用demo .ipho ...
- IOS中定时器NSTimer的开启与关闭
调用一次计时器方法: myTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(scro ...
- 【转】iOS中定时器NSTimer的使用
原文网址:http://www.cnblogs.com/zhulin/archive/2012/02/02/2335866.html 1.初始化 + (NSTimer *)timerWithTimeI ...
- iOS中定时器NSTimer的使用-备用
1.初始化 + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelect ...
- 【转】IOS中定时器NSTimer的开启与关闭
原文网址:http://blog.csdn.net/enuola/article/details/8099461 调用一次计时器方法: myTimer = [NSTimer scheduledTime ...
- 【转】 IOS中定时器NSTimer的开启与关闭
原文网址:http://blog.csdn.net/enuola/article/details/8099461 调用一次计时器方法: myTimer = [NSTimer scheduledTime ...
- 蜗牛爱课- iOS中定时器NSTimer使用
调用一次计时器方法: //不重复,只调用一次.timer运行一次就会自动停止运行 self.locationTimer = [NSTimer target:self selector: @selec ...
- iOS中定时器NSTimer的使用/开启与关闭
一.只调用一次计时器方法: //不重复,只调用一次.timer运行一次就会自动停止运行 myTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 ...
- ios 中定时器:NSTimer, CADisplayLink, GCD
#import "ViewController.h" #import "RunloopViewController.h" @interface ViewCont ...
随机推荐
- TensorFlow入门测试程序
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist=input_data. ...
- hive distcp数据同步
-- 同步HDFS数据(shell执行) hadoop distcp \ -Dmapred.job.queue.name=queue_name \ -update \ -skipcrccheck hd ...
- python解决excel工作薄合并处理(openpyxl处理excel2010以上版本)
前段时间使用xlrd.xlwt对文件进行处理(https://www.cnblogs.com/pinpin/p/10287491.html),但是只能处理excel2010以下版本,所以又写了个处理e ...
- ORACLE CBC LATCH 检查
###############1.DB meet latch: cache buffers chains event from awr report ,check latch: cache buffe ...
- str 操作方法
# str 类,字符串 # name ='alex' # 首字母变大写 # test ='alex' # v= test.capitalize() # print(v) # # 大写全部变小写 # t ...
- Trees on the level UVA - 122 (二叉树的层次遍历)
题目链接:https://vjudge.net/problem/UVA-122 题目大意:输入一颗二叉树,你的任务是按从上到下,从左到右的顺序输出各个结点的值.每个结点都按照从根节点到它的移动序列给出 ...
- visual stdio使用
现在转换使用visual stdio,因为很多和以前的快捷键不同,也不打算换了,这样可移动性应该更好吧. 1.注释代码, 首先按下ctrl + k,然后再按下ctrl + c 2.取消注释,首先按下c ...
- Linux下判断磁盘是SSD还是HDD的几种方法
环境介绍 Fedora release 25 (Twenty Five) 判断方法 方法一 判断cat /sys/block/*/queue/rotational的返回值(其中*为你的硬盘设备名称,例 ...
- pat05-图1. List Components (25)
05-图1. List Components (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue For a ...
- wait/notify
某面试题,实现一个生产者——消费者模型 题目:采用多线程技术,通过wait/notify,设计实现一个符合生产者和消费者问题的程序,对某一个对象(枪膛)进行操作,其最大容量是20颗子弹,生产者线程是一 ...