Skip to content

Instantly share code, notes, and snippets.

View hanfengs's full-sized avatar

hanfengs

  • Beijing China
View GitHub Profile
@hanfengs
hanfengs / method.h
Last active April 4, 2019 02:15
[iOS相机权限] 请求相机权限以及弹框 #权限
- (void)QRCodeScanVC:(UIViewController *)scanVC {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch (status) {
case AVAuthorizationStatusNotDetermined: {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:scanVC animated:YES];
@hanfengs
hanfengs / gist:e4fa0dacb46c5e9cf507e7ee57682daa
Last active April 4, 2019 02:16
[每日弹框] 本地每天一次的操作,比如签到;提醒升级弹框等等 #每日签到
NSDate *nowDate = [NSDate date];
NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];
[dataUser setObject:nowDate forKey:@"nowDate"];
[dataUser synchronize];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSDate *now = [NSDate date];
NSDate *agoDate = [userDefault objectForKey:@"nowDate"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
@hanfengs
hanfengs / tips.md
Last active April 4, 2019 02:26
[gist tips] #tips 记录某些

Tips

做记录

方便管理

强调部分

@hanfengs
hanfengs / delegate.m
Last active April 18, 2019 09:06
[强制使用系统键盘] 强制使用系统键盘 #keyboard
//https://www.cnblogs.com/syios/p/7692566.html
//https://www.jianshu.com/p/35219655d187
-(BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(UIApplicationExtensionPointIdentifier)extensionPointIdentifier{
// 整个app应用内禁用第三方键盘
// if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {
// return NO;
// }
@hanfengs
hanfengs / font.m
Created April 24, 2019 10:31
[打印iOS系统字体] 打印iOS系统字体 #Font
NSArray *familyNames = [UIFont familyNames];
for(NSString *familyName in familyNames ){
printf("Family: %s \n", [familyName UTF8String]);
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for(NSString *fontName in fontNames) {
@hanfengs
hanfengs / kvo.m
Created May 21, 2019 08:02
[KVO] kvo使用说明 #KVO
//第一个参数 observer:观察者 (这里观察self.myKVO对象的属性变化)
//第二个参数 keyPath: 被观察的属性名称(这里观察 self.myKVO 中 num 属性值的改变)
//第三个参数 options: 观察属性的新值、旧值等的一些配置(枚举值,可以根据需要设置,例如这里可以使用两项)
//第四个参数 context: 上下文,可以为 KVO 的回调方法传值(例如设定为一个放置数据的字典)
[self.myKVO addObserver:self
forKeyPath:@"num"
options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew
context:nil];
@hanfengs
hanfengs / gif.m
Last active May 21, 2019 08:22
[gif播放一次] gif播放一次 #gif
//GIF 的播放次数是 GIF 图片本身的属性,这应该是只读的。想要控制循环次数,大概有几种方法:
//1.如果你不能控制 GIF 图片内容,那你可以监听 YYAnimatedImageView 的 currentAnimatedImageIndex 属性,当播放到最后一帧时,调用 stopAnimating 停止动画。
//2.子类化 YYImage,把循环次数这个属性暴露出来:ibireme/YYImage#1
//3.用比较 hack 的方法来做:
if ([image isKindOfClass:[YYImage class]]) {
YYImageDecoder *decoder = [image valueForKey:@"_decoder"];
@hanfengs
hanfengs / line.m
Created June 3, 2019 03:08
[虚线] 画虚线 #虚线
- (void)line{
UIImageView *iView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
[self.view addSubview:iView];
UIGraphicsBeginImageContext(iView.frame.size); //参数size为新创建的位图上下文的大小
[iView.image drawInRect:CGRectMake(0, 0, iView.frame.size.width, iView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare); //设置线段收尾样式
CGFloat length[] = {2,1}; // 线的宽度,间隔宽度
@hanfengs
hanfengs / yycache.m
Created June 19, 2019 07:50
[yycache]
@interface TSUserLearnFlowInfo : NSObject<NSCoding>
@property (nonatomic, copy) NSString *homeworkId;
@property (nonatomic, copy) NSString *useTime;
@property (nonatomic, strong) NSArray *practiceIds;
@property (nonatomic, strong) NSArray *audioUrls;
@property (nonatomic, strong) NSArray *audioMarks;
@end
@implementation TSUserLearnFlowInfo
@hanfengs
hanfengs / plist.m
Created June 19, 2019 08:25
[plist]
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [path stringByAppendingPathComponent:@"UserProgress.plist"];
NSDictionary *dict = @{@"age" : @26,@"name" : @"LayneCheung"};
[dict writeToFile:filePath atomically:YES];
NSArray *dataArray = @[@56,@"asdfa"];
[dataArray writeToFile:filePath atomically:YES];