iOS 工作中遇到的问题 (六)

判断app是不是第一次启动

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]){  
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];  
//第一次启动  
}else{  
//不是第一次启动了  
}  

开启系统自带侧滑返回

// Objective - C
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
// swift
navigationController.interactivePopGestureRecognizer.delegate = self

保持手机常亮

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

获取到NSDate差(秒数)

time1和time2是你之前得到的日期。
NSTimeInterval date1 = [time1 timeIntervalSinceReferenceDate]; 
NSTimeInterval date2 = [time2 timeIntervalSinceReferenceDate]; 
long interval = date1 - date2;

时间字符串和NSDate互转

由 NSDate 转换为 NSString:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", strDate);
[dateFormatter release];

结果:
2010-08-04 16:01:03


由 NSString 转换为 NSDate:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
NSLog(@"%@", date);
[dateFormatter release];

字符串处理

1.截取字符串

NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];//截取掉下标7之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:2];//截取掉下标2之前的字符串
NSLog(@"截取的值为:%@",string);


2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
NSLog(@"截取的值为:%@",string);


3.分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";

NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf

UIButton 文本自动换行

Button.titleLabel!.numberOfLines=0 

绘制图片圆角

- (UIImage *)hyb_imageWithCornerRadius:(CGFloat)radius {
  CGRect rect = (CGRect){0.f, 0.f, self.size};

  UIGraphicsBeginImageContextWithOptions(self.size, NO, UIScreen.mainScreen.scale);
  CGContextAddPath(UIGraphicsGetCurrentContext(),
                   [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
  CGContextClip(UIGraphicsGetCurrentContext());

  [self drawInRect:rect];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  return image;
}

苹果Xcode帮助文档阅读指南

http://ourcoders.com/thread/show/117/

检测项目中是否调用了私有方法

https://github.com/nomenas/APIChecker

检测网络状态

1.注册网络状态改变触发的监控方法。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netStateChanged:) name:kReachabilityChangedNotification object:nil];
    //先触发网络状态改变的方法
     _reach = [Reachability reachabilityWithHostName:@"http://www.baidu.com"];
    [_reach startNotifier];
   //网络状态方法改变触发下面检测的方法
    _reach = [Reachability reachabilityForInternetConnection];
    [_reach startNotifier];
2.在监控的方法里获取当前的网络状态,判断是哪一种网络。
-(void)netStateChanged:(NSNotification *)notification{
    NSString *tips;
    NetworkStates currentStates = [NetworkTool getNetworkStates];
    switch (currentStates) {
        case NetworkStatesNone:
            tips = @"当前无网络, 请检查您的网络状态";
            break;
        case NetworkStates2G:
            tips = @"切换到了2G网络";
            break;
        case NetworkStates3G:
            tips = @"切换到了3G网络";
            break;
        case NetworkStates4G:
            tips = @"切换到了4G网络";
            break;
        case NetworkStatesWIFI:
            tips = @"无线网";
            break;
        default:
            break;
    }
  }

利用mastery做动画

1.控件的原始约束
self.animationBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
    [self.animationBtnsetTitle:@"动画按钮"forState:UIControlStateNormal];
    self.animationBtn.backgroundColor=[UIColorgrayColor];
    
    [self.animationBtnaddTarget:selfaction:@selector(onGrowButtonTaped:)forControlEvents:UIControlEventTouchUpInside];
    [self.viewaddSubview:self.animationBtn];
    self.scacle =1.0;
    
    [self.animationBtnmas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.view);
        make.width.height.mas_equalTo(100);
        make.width.height.lessThanOrEqualTo(self.view);
    }];
2.点击开始做动画的时候从新做约束
- (void)onGrowButtonTaped:(UIButton *)sender {
    [UIViewanimateWithDuration:2animations:^{
        [self.animationBtnmas_remakeConstraints:^(MASConstraintMaker *make){
            make.left.top.equalTo(self.view);
            make.width.height.mas_equalTo(200);
        }];
        [self.viewlayoutIfNeeded];//强制绘制
    }];
    
}

利用终端MP3转caf

打开终端(Terminal),先进入wav文件所在的目录,输入命令:
/usr/bin/afconvert -f caff -d LEI16 "bullet_fire_02_30.wav"

配置推送证书

http://www.jianshu.com/p/8b6ad7294e71

音频合成

https://github.com/Tbwas/AudioMerge

替换系统cell的灰色箭头图标

[self setAccessoryView:self.arrowView];

你可能感兴趣的:(iOS 工作中遇到的问题 (六))