IOS--GCD修改主线程UI属性
2016-03-02 15:24
423 查看
TestController.m
#import "TestController.h" #import "TestView.h" @interface TestController() @property(nonatomic,strong)UIButton *button; @property(nonatomic,strong)UIProgressView *progress; @end @implementation TestController - (void)viewDidLoad { [super viewDidLoad]; _button = [UIButton buttonWithType:UIButtonTypeSystem]; _button.frame = CGRectMake(0, 20, 100, 20); [_button setTitle:@"Hello" forState:UIControlStateNormal]; [_button addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside]; _progress = [[UIProgressView alloc]initWithFrame:CGRectMake(20, 60, 240, 25)]; [self.view addSubview:_button]; [self.view addSubview:_progress]; } //GCD -(void)start:(UIButton*)sender { dispatch_queue_t queeue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queeue, ^{ [self thLoop]; }); } -(void)thLoop { float i; while (i<1) { i+=0.01; [NSThread sleepForTimeInterval:0.1]; //修改主线程UI属性,需要调用dispatch_get_main_queue()函数 dispatch_async(dispatch_get_main_queue(), ^{ self.progress.progress = i; }); } } @end
相关文章推荐
- UICollectionViewController相关注意事项
- web.xml配置文件中<async-supported>true</async-supported>报错的解决方案
- UIViewController的完整生命周期
- Building for Erle-Brain 2
- UICollectionView的使用
- 队列(Queue)--环形队列、优先队列和双向队列
- codeforces632D. Longest Subsequence (最小公倍数)
- 利用CAShapeLayer和UIBezierPath结合画梯形图
- [置顶] iOS-UIImage imageWithContentsOfFile 和 imageName 对比
- API Guides(六)—— Create a Search Interface To Drag and Drop
- MQTT libmosquitto源码分析
- mui 重写back 调用back方法,实现返回就即时刷新页面
- Qt on Android:让 Qt Widgets 和 Qt Quick 应用全屏显示
- UICollectionVIew的简单使用
- HDU-1711 Number Sequence (kmp)
- Cell嵌套UITableView自动布局
- Access restriction : The type 4000 BASE64Decoder is not accessible due to restriction on required library
- easyui datalist按组多选
- Blue border around video file
- 百度富文本编辑器ueditor使用总结