Skip to content

Instantly share code, notes, and snippets.

View coderiding's full-sized avatar
💭
I may be slow to respond.

宇哥 coderiding

💭
I may be slow to respond.
View GitHub Profile
我问了gitee官方号,后来让我加QQ群,官方解答是,gitee普通版的page不支持自动更新,pro版本才支持。唉,真的辣鸡,要不是github的加速被国内墙了,访问慢。我会用gitee,强烈要求实现自动更新。
mx:借鉴了SVProgressHUD的方式
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"];
maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage];
maskLayer.frame = _indefiniteAnimatedLayer.bounds;
DEMO:https://github.com/awliu/demo_dispatch_group
dispatch_group 基本语法
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 执行第一个1个耗时的异步操作
});
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
主线程定时执行
@property (nonatomic, strong) dispatch_source_t timer;
// 【主线程】:2秒后隔2秒执行1次共执行多次
- (void)setupMainThreadJJGCDTimerWithStartTimeSinceNow:(float)satrttime interval:(float)intervaltime repeatcount:(int)repeatcount
{
dispatch_queue_t queue = dispatch_get_main_queue();
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(satrttime * NSEC_PER_SEC));
主线程延迟
// 【主线程】:延迟2秒后执行1次
- (void)setupMainThreadDelayInSecond:(float)second{
double delayInSeconds = second;
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^(void){
// 执行事件
NSLog(@"setupMainThreadDelayInSecond------------%@", [NSThread currentThread]);
});
方法1:使用dispatch_get_main_queue
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 执行耗时的异步操作...CODE
NSLog(@" 处理子线程工作");
[NSThread sleepForTimeInterval:2];
dispatch_async(dispatch_get_main_queue(), ^{
// 回到主线程,执行UI刷新操作
NSLog(@" 处理主线程工作");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// 只执行1次的代码(这里面默认是线程安全的)
});
单例(初始化情况少)
//id 可以是任何类名
+ (instancetype)sharedInstance{
static id _instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
});
return _instance;
typedef void(^handler)(void);
typedef void(^completion)(BOOL finished);
@property handler handler;
@property completion completion;
效果图链接:https://raw.githubusercontent.com/codeRiding/github_pic_0001/master/2020-03-26 21.01.10.gif
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIView* bgSelectionView = [UIView new];
bgSelectionView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = bgSelectionView;
}
https://gist.github.com/0c984c8a7b66933d75ee2fe5041c4ce6