Skip to content

Instantly share code, notes, and snippets.

View hanfengs's full-sized avatar

hanfengs

  • Beijing China
View GitHub Profile
@hanfengs
hanfengs / moveItemAtPath.m
Created July 14, 2021 10:59
[沙盒文件移动]
NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
NSString *filePath = [path stringByAppendingPathComponent:@"OralEvaluationCache"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:filePath]){
[fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *fileName = [NSString stringWithFormat:@"%llu.%@", tickCountOfCPU(), [recordPath pathExtension]];
NSString *moveToPath = [filePath stringByAppendingPathComponent:fileName];
NSError *moveError;
@hanfengs
hanfengs / color.m
Last active January 17, 2023 06:27
[渐变色]
// [self IGC_setupGradientLayerWithStartColor:HEXCOLOR(0xFFD64E) endColor:HEXCOLOR(0xFFB918)];
// [self IGC_setupGradientLayerWithStartColor:HEXCOLOR(0xFFB674) endColor:HEXCOLOR(0xFF6D0D)];
- (void)IGC_setupGradientLayerWithStartColor:(UIColor *)startColor endColor:(UIColor *)endColor{
[self layoutIfNeeded];
CAGradientLayer *gl = [CAGradientLayer layer];
gl.frame = self.bounds;
@hanfengs
hanfengs / anmation.m
Created May 21, 2021 09:23
[动画效果]
// 删除抖动效果
- (void)IGC_shakeAnimationForView:(UIView *)view {
CALayer *viewLayer = view.layer;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
[animation setFromValue:[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform,-0.12,0.0,0.0,0.12)]];
[animation setToValue:[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform,0.12,0.0,0.0,0.12)]];
[animation setAutoreverses:YES];
[animation setDuration:0.2];
[animation setRepeatCount:MAXFLOAT];
@hanfengs
hanfengs / masonry.m
Created May 20, 2021 03:44
[masonry做动画]
{
[self insertSubview:self.pandaButton aboveSubview:self.collectionView];
[self.pandaButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(84);
make.right.equalTo(self);
make.bottom.equalTo(self).offset(-80);
}];
// [self scrollViewWillBeginDecelerating:self.collectionView];
@hanfengs
hanfengs / down.m
Created April 26, 2021 13:55
[批量按顺序下载-基于AFN3.0]
https://blog.csdn.net/fys_0801/article/details/80180924
-(void)xx{
// 创建队列
dispatch_queue_t queue = dispatch_queue_create("com.download.task", DISPATCH_QUEUE_SERIAL);
NSString *str = @"https://www.****.com/***.jpg";
//设置信号总量为1,保证只有一个进程执行
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
@hanfengs
hanfengs / UILabel.m
Last active March 9, 2021 03:33
[UILabel文本的宽度和高度]
https://blog.csdn.net/qq_36557133/article/details/81106027
https://blog.csdn.net/MinggeQingchun/article/details/52583709
https://cloud.tencent.com/developer/article/1332213
在iOS开发中我们都会遇到界面搭建中UILabel文本的宽度和高度的不可预估带来的适配或者约束中的麻烦。
如果使用sb进行界面布局,只要label不设置宽、高约束就会自适应。
1.单行
@hanfengs
hanfengs / countDown.m
Created March 3, 2021 08:13
[倒计时框动态布局]
@property (nonatomic, strong) UIView *dayTimerContainerView;//!< 存放倒计时天、小时的View
[self.bgScrollContentView addSubview:self.dayTimerContainerView];
[self.dayTimerContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgScrollContentView).mas_offset(16);
make.height.mas_equalTo(37);
make.centerX.equalTo(self.bgScrollContentView);
}];
@hanfengs
hanfengs / camera.m
Created March 2, 2021 04:02
[相机裁剪框]
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
if (self.model.crop == 1) {
picker.allowsEditing = YES;
UIImageView *overLayImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];
overLayImg.image = [UIImage imageNamed:@"exerciseNote_icon"];
@hanfengs
hanfengs / associated.m
Created January 23, 2021 15:17
关联对象的简单使用
- (void)setName:(NSString *)name{
objc_setAssociatedObject(self, @selector(name), name, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSString *)name{
// 隐式参数
// _cmd == @selector(name)
return objc_getAssociatedObject(self, _cmd);
}
@hanfengs
hanfengs / segment.m
Created December 28, 2020 10:21
[segment自定义]
#import "IGCUITabLayout.h"
@interface IGCUITabLayout()
@property (nonatomic, strong) NSArray *tabItemsArray;
@property (nonatomic, strong) UIScrollView *scrollView;
@end