#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//////---------runloop的获取--------////////
//Cocoa中获取runloop的方法
//获取当前线程的runloop
NSRunLoop *currentRunloop = [NSRunLoop currentRunLoop];
//获取主线程runloop
NSRunLoop *mainrunloop = [NSRunLoop mainRunLoop];
NSLog(@"currentRunloop is:%@",currentRunloop);
NSLog(@"mainrunloop is:%@",mainrunloop);
//Core Foundition获取runloop的方法
//获取当前线程的runloop
CFRunLoopGetCurrent();
//获取主线程runloop
CFRunLoopGetMain();
////////-------runloop的mode------/////////
//创建nstimer
// NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(time) userInfo:nil repeats:YES];
//该种方式创建nstimer 将会以默认的模式添加到runloop NSDefaultRunLoopMode
NSTimer *scheduleTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(scheduleTime) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:scheduleTimer forMode:NSRunLoopCommonModes];
//对UI控件拖动时 runloop的执行模式为UITrackingRunLoopMode
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 100, 200, 500)];
scrollView.contentSize = CGSizeMake(500, 800);
scrollView.backgroundColor = [UIColor redColor];
[self.view addSubview:scrollView];
}
-(void)time
{
NSLog(@"------timer--------");
}
-(void)scheduleTime
{
NSLog(@"------stimer--------");
}
@end
多线程 RunLoop
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 又来到了一个老生常谈的问题,应用层软件开发的程序员要不要了解和深入学习操作系统呢? 今天就这个问题开始,来谈谈操...