iOS 自定义打印
方式一:
//DEBUG 模式下打印日志,当前行
#ifdef DEBUG (__OPTIMIZE__)
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif
当定义__OPTIMIZE__时,发布时只需做如下设置:
将debug改为Release即可
当定义DEBUG时,设置DEBUG如下:
发布无需做更改
3、在工程中配置reveal链接到模拟器 打开工程后,在appdeleget中的didfinished:方法中打下断点,并按下图编辑断点:
方式二:
//重写NSLog,Debug模式下打印日志和当前行数
#ifdef DEBUG
#define NSLog(fmt,...)\
do{ \
NSLog((@"%s:(Line:%d)" fmt),__func__,__LINE__,##__VA_ARGS__); \
}while(0)
#else
#define NSLog(fmt,...){}
#endif
coreText
CGContextSetTextMatrix(context,CGAffineTransformIdentity);设置字形变换矩阵为CGAffineTransformIdentity,也就是说每一个字形都不做图形变换。
CFArrayGetValueAtIndex:使用
NSArray *arr =@[@"1", @"2", @"3",@"4", @"5"];
CFArrayRef arrRf = (__bridge CFArrayRef)arr;
for (inti=0; i<arr.count; i++) {
NSLog(@"%@",CFArrayGetValueAtIndex(arrRf, i));
}
CFRelease(arrRf);
求一串字符串(含汉字)的字符数
-(NSUInteger) unicodeLengthOfString: (NSString *) text {
NSUInteger asciiLength = 0;
for (NSUInteger i = 0; i < text.length; i++) {
unichar uc = [text characterAtIndex: i];
asciiLength += isascii(uc) ? 1 : 2;
}
asciiLength : 就是字符的总数;;;;
///———————————
NSUInteger unicodeLength = asciiLength / 2;
if(asciiLength % 2) {
unicodeLength++;
}
///——————————— 这个地方返回的是字符串长度。
return unicodeLength;
}
MutableCopy与Copy
只有不可变对象的copy是浅拷贝,其余都是深拷贝
MutableCopy: 创建一个新的可变对象,并初始化原对象的值,新对象的引用计数为1;
copy:分两种情况:
(1) 对于原对象是不可变对象:则直接返回原对象,并将其引用计数加1;
(2) 对于原对象是可变的对象,则创建一个新的不可变对象,并初始化原对象的值,新对象的引用计数为1;
Reveal 使用
1、打开命令窗口,在根目录下创建一个.lldbinit文件。输入下列命令,后回车;
vim ~/.lldbinit;
2、回车后,输入下列代码:
command alias reveal_load_sim expr (
void
*)dlopen(
"/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib"
,
0x2
);
command alias reveal_load_dev expr (
void
*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@
"libReveal"
ofType:@
"dylib"
] cStringUsingEncoding:
0x4
],
0x2
);
command alias reveal_start expr (
void
)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@
"IBARevealRequestStart"
object:nil];
command alias reveal_stop expr (
void
)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@
"IBARevealRequestStop"
object:nil];
以上是四句命令,命令的意思是,给lldb设置了4个别名,这四个别名的意义是:
reveal_load_sim:模拟器加载reveal时调用的动态链接库
reveal_load_dev:真机加载reveal时调用的动态链接库
reveal_start:启动reveal的调试功能
reveal_stop:关闭reveal的调试功能
在输入完这些命令后,输入以下命令,按一下回车就保存并退出编辑模式了
:wq
打完断点后,就可以选择模拟器运行工程了,当工程跑起来后,打开reveal,点击左上角的工程选择,会看到我们的工程。
translationInView 与locationInView的区别:
translationInView:会将父视图坐标转换,而后者不会进行转换
iOS 中废弃的方法注释:
__deprecated_msg("Method deprecated. Use `sharePlaySound:`")
iOS 中打印子控件:
recursiveDescription
视图切换中的错误:
Unbalanced calls to begin/end appearance transitions for<> 处理:
第一种异步加延时:
double delayInSecond = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW,delayInSecond * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue, ^(void) {
[viewController presentModalViewController:VC animated:yes];
});
第二种直接异步无需延时也可:
dispatch_async(dispatch_get_main_queue(), ^(void){
[rootvc presentViewController:userSetNav animated:NOcompletion:^{
}];
});
Core Animation中可动画的属性:
搜索关键字:animatable properties