转载:http://www.jianshu.com/p/1ff9e44ccc78
总结了几个月的东西终于能和大家分享了,不多说,直接看东西!
1、禁止手机睡眠
[UIApplication
sharedApplication].idleTimerDisabled = YES
2、隐藏某行cell
- (
CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
3、禁用button高亮
button.adjustsImageWhenHighlighted =
NO;
或者在创建的时候
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
4、tableview遇到这种报错failed to obtain a cell from its dataSource
是因为你的cell被调用的早了。先循环使用了cell,后又创建cell。顺序错了可能原因:1、xib的cell没有注册 2、内存中已经有这个cell的缓存了(也就是说通过你的cellId找到的cell并不是你想要的类型),这时候需要改下cell的标识
5、cocoa pods报这个错误:unable to access 'https://github.com/facebook/pop.git/': Operation timed out after 0 milliseconds with 0 out of 0 bytes received
解决办法:原因可能是网络问题,网络请求超时了,只需要重试就行了
6、cocoa pods 出现ERROR: While executing gem ... (Errno::EPERM)
解决办法:https://segmentfault.com/q/1010000002926243
7、动画切换window的根控制器
8、去除数组中重复的对象
NSArray *newArr = [oldArr
valueForKeyPath:@“@distinctUnionOfObjects.self"];
9、编译的时候遇到 no such file or directory: /users/apple/XXX
是因为编译的时候,在此路径下找不到这个文件,解决这个问题,首先是是要检查缺少的文件是不是在工程中,如果不在工程中,需要从本地拖进去,如果发现已经存在工程中了,或者拖进去还是报错,这时候需要去build phases中搜索这个文件,这时候很可能会搜出现两个相同的文件,这时候,有一个路径是正确的,删除另外一个即可。如果删除了还是不行,需要把两个都删掉,然后重新往工程里拖进这个文件即可
build phases
10、iOS8系统中,tableView最好实现下-tableView: heightForRowAtIndexPath:这个代理方法,要不然在iOS8中可能就会出现显示不全或者无法响应事件的问题
11、iOS8中实现侧滑功能的时候这个方法必须实现,要不然在iOS8中无法侧滑
12、三个通知
NSSystemTimeZoneDidChangeNotification监听修改时间界面的两个按钮状态变化UIApplicationSignificantTimeChangeNotification 监听用户改变时间 (只要点击自动设置按钮就会调用) NSSystemClockDidChangeNotification 监听用户修改时间(时间不同才会调用)
13、SDWebImage本地缓存有时候会害人。如果之前缓存过一张图片,即使下次服务器换了这张图片,但是图片url没换,用sdwebimage下载下来的还是以前那张,所以遇到这种问题,不要先去怼服务器,清空下缓存再试就好了。
14、上线前注意:
1)、删掉代码中所有的测试代码2)、如果后台有审核模式,提醒后台开启此模式3)、主流程再跑一跑4)、全局搜索waring,检查所有标记waring的地方
15、跳进app权限设置
16、给一个view截图
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
17、开发中如果要动态修改tableView的tableHeaderView或者tableFooterView的高度,需要给tableView重新设置,而不是直接更改高度。正确的做法是重新设置一下tableView.tableFooterView = 更改过高度的view。为什么?其实在iOS8以上直接改高度是没有问题的,在iOS8中出现了contentSize不准确的问题,这是解决办法。
18、注意对象为nil的时候,调用此对象分类的方法不会执行
19、collectionView的内容小于其宽高的时候是不能滚动的,设置可以滚动:
collectionView.alwaysBounceHorizontal = YES
20、设置navigationBar上的title颜色和大小
[
self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor youColor], NSFontAttributeName : [UIFont systemFontOfSize:15]}]
21、颜色转图片
+ (
UIImage *)cl_imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
22、view设置圆角
#define ViewBorderRadius(View, Radius, Width, Color)
\
\
[View.layer setCornerRadius:(Radius)];\ [View.layer setMasksToBounds:YES];\ [View.layer setBorderWidth:(Width)];\ [View.layer setBorderColor:[Color CGColor]] // view圆角
23、强/弱引用
#define WeakSelf(
type) __weak typeof(type) weak##type = type;
24、由角度转换弧度
#define DegreesToRadian(x) (M_PI * (x) / 180.0)
25、由弧度转换角度
#define RadianToDegrees(
radian) (radian*180.0)/(M_PI)
26、获取图片资源
#
define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
27、获取temp
#
define PathTemp NSTemporaryDirectory()
28、获取沙盒 Document
#
define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
29、获取沙盒 Cache
#
define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
30、GCD代码只执行一次
#define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
31、自定义NSLog
#ifdef DEBUG
#define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else #define NSLog(...) #endif
32、Font
#define FontL(s) [UIFont systemFontOfSize:s weight:UIFontWeightLight]
#define FontR(s) [UIFont systemFontOfSize:s weight:UIFontWeightRegular] #define FontB(s) [UIFont systemFontOfSize:s weight:UIFontWeightBold] #define FontT(s) [UIFont systemFontOfSize:s weight:UIFontWeightThin] #define Font(s) FontL(s)
33、FORMAT
#define FORMAT(f, ...) [NSString stringWithFormat:f, ## __VA_ARGS__]
34、在主线程上运行
#define kDISPATCH_MAIN_THREAD(
mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock)
35、开启异步线程
#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(
globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl)
36、通知
#define NOTIF_ADD(n, f) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(f) name:n object:nil] #define NOTIF_POST(n, o) [[NSNotificationCenter defaultCenter] postNotificationName:n object:o] #define NOTIF_REMV() [[NSNotificationCenter defaultCenter] removeObserver:self]
37、随机颜色
+ (
UIColor *)RandomColor {
NSInteger aRedValue = arc4random() % 255;
NSInteger aGreenValue = arc4random() % 255; NSInteger aBlueValue = arc4random() % 255; UIColor *randColor = [UIColor colorWithRed:aRedValue / 255.0f green:aGreenValue / 255.0f blue:aBlueValue / 255.0f alpha:1.0f]; return randColor; }
38、获取window
+(
UIWindow*)getWindow {
UIWindow* win = nil;
39、修改textField的placeholder的字体颜色、大小
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
40、统一收起键盘
[[[UIApplication sharedApplication] keyWindow] endEditing:YES]
41、控制屏幕旋转,在控制器中写
42、获取app缓存大小
- (
CGFloat)getCachSize {
NSUInteger imageCacheSize = [[SDImageCache sharedImageCache] getSize];
43、清理app缓存
- (
void)handleClearView {
44、模型转字典
static NSSet *classes;
- (NSMutableDictionary *)getParameterDictionary {
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; Class c = self.class; while (c) { unsigned count; objc_property_t *properties = class_copyPropertyList([c class], &count); for (int i = 0; i < count; i++) { NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])]; dict[key] = [self valueForKey:key]; } free(properties);
45、交换两个方法实现
Class aClass = [self class];
SEL originalSelector = @selector(viewWillAppear:);
SEL swizzledSelector = @selector(xxx_viewWillAppear:); Method originalMethod = class_getInstanceMethod(aClass, originalSelector); Method swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector); BOOL didAddMethod = class_addMethod(aClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod)
46、打印百分号和引号
NSLog(@"%%");
NSLog(@"\"");
47、几个常用权限判断
if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
NSLog(@"没有定位权限");
}
AVAuthorizationStatus statusVideo = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (statusVideo == AVAuthorizationStatusDenied) { NSLog(@"没有摄像头权限"); }
48、获取手机型号
+ (NSString *)getDeviceInfo {
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString
stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G"; if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS"; if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4"; if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4"; if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4"; if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5"; if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5"; if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c"; if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c"; if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s"; if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s"; if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus"; if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6"; if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s"; if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
转载于:https://www.cnblogs.com/lujianwenance/p/7085462.html
相关资源:各显卡算力对照表!