多线程 RunLoop

作者: 一枚小菜鸟 | 来源:发表于2016-05-03 19:28 被阅读123次
    #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

        本文链接:https://www.haomeiwen.com/subject/mlhrrttx.html