iOS.tips

1.关于app搜身(NextPreviousSubmitting the App to App Review
在 “Other Linker Flags” 中添加
[cc lang=’c’]
-Wl,-rename_section,__TEXT,__cstring,__RODATA,__cstring
-Wl,-rename_section,__TEXT,__const,__RODATA,__const
-Wl,-rename_section,__TEXT,__objc_methname,__RODATA,__objc_methname
-Wl,-rename_section,__TEXT,__objc_classname,__RODATA,__objc_classname
-Wl,-rename_section,__TEXT,__objc_methtype,__RODATA,__objc_methtype
[/cc]

2. 块{}
[cc lang=’c’]
NSMutableDictionary *dic = @{@”type”:
({ NSMutableArray *arr = [NSMutableArray array];
for (int i = 0 ; i < 5; i ++) {
[arr addObject:@”name”];
}
arr;
})
};

/** log(dic)
dic = {
type = (
name,
name,
name,
name,
name
);
}
*/
[/cc]

 

2.1 代码收缩快捷键 shift+command+alt  左键 or 右键
3.app进去前后台
[cc lang=’c’]
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil]; // 监听是否触发home键进入后台

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil]; // 监听是否重新进入程序
[/cc]
4.判断是否是他的子视图
[cc lang=’c’]
BOOL issub = [subview isDescendantOfView:self.view];
[/cc]
5.判断是否遵循特定协议
[cc lang=’c’]
if ([self.selectedController conformsToProtocol:@protocol(RefreshPtotocol)]) {
[self.selectedController performSelector:@selector(onTriggerRefresh)];
}
[/cc]
6.开发中用到的一些路径
[cc lang=’c’]
模拟器的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
文档安装位置:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
插件保存路径:
~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins
自定义代码段的保存路径:
~/Library/Developer/Xcode/UserData/CodeSnippets/
如果找不到CodeSnippets文件夹,可以自己新建一个CodeSnippets文件夹。
证书路径
~/Library/MobileDevice/Provisioning Profiles
[/cc]
7.去掉空格
[cc lang=’c’]
去掉所有的空格
[string stringByReplacingOccurrencesOfString:@” ” withString:@””]
去掉首尾的空格
[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[/cc]
8.抖动动画
[cc lang=’c’]
//1, 创建核心动画
CAKeyframeAnimation *keyAnima = [CAKeyframeAnimation animation];
//2, 告诉系统执行什么动画。
keyAnima.keyPath = @”transform.rotation”;
keyAnima.values = @[@(-M_PI_4 /90.0 * 5),@(M_PI_4 /90.0 * 5),@(-M_PI_4 /90.0 * 5)];
// 3, 执行完之后不删除动画
keyAnima.removedOnCompletion = NO;
// 4, 执行完之后保存最新的状态
keyAnima.fillMode = kCAFillModeForwards;
// 5, 动画执行时间
keyAnima.duration = 0.2;
// 6, 设置重复次数。
keyAnima.repeatCount = MAXFLOAT;
// 7, 添加核心动画
[self.showVerisonLabel.layer addAnimation:keyAnima forKey:nil];
[/cc]
9.UItableViewCell分割线从左边0开始
[cc lang=’c++’]
– (void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
}

if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
}

– (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
[/cc]

 

10.通过appName来区分Debug,release

选择xcode>Editor>Add Build Setting>Add User-Defined Setting

然后Target >Info>Bundle display name(value为user-Defined自己定义的名字)就好;

11. 常用lldb和断点调试
(lldb) expression修改变量的值eqi_cc_lldb_expr
eqi_cc_lldb_test

(lldb) call调用
(lldb) call [self.view setBackgroundColor:[UIColor redColor]]

(lldb) image寻址
(lldb) image lookup –address 0x0000000100009a03

license:  The LLDB Debugger         facebook/chisel

12.获取当前UIWebView的URL
[cc lang=’c’]
// 方式一
NSString *currentURL =[self.webView stringByEvaluatingJavaScriptFromString:@”document.URL”];
// 方式二
NSString *currentURL = self.request.URL;
[/cc]

13.隐藏navigationBar底部线条
[cc lang=’c’]
– (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor purpleColor]]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

}

– (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}

[/cc]

14.删除NSString两边空格
[cc lang=’c’]
NSString *string = @” eqi.cc zhece.com “;
NSString *noSpaceString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; //eqi.cc zhece.com
[/cc]

15.不定多参数
[cc lang=’c’]
// NS_FORMAT_FUNCTION(1, 2) 第一位是格式符号,从第二位开始; NS_REQUIRES_NIL_TERMINATION nil结尾
– (NSArray *)arrayWithObjects:(id)firstObj, …NS_REQUIRES_NIL_TERMINATION{

NSMutableArray *tempArray = [NSMutableArray array];
va_list argList;

if (firstObj) {
[tempArray addObject:firstObj];
va_start(argList, firstObj);
id temp;
while ((temp = va_arg(argList, id))) {
[tempArray addObject:temp];
NSLog(@”—%@”,tempArray);
}
}
return tempArray;
}
[/cc]

16. 查看.a文件,函数,变量
ar -d xx.a

lipo -info xx.a

nm -A xx.a

[cc lang=’c’]
// nm -help
General options:

-B – Alias for –format=bsd
-P – Alias for –format=posix
-aarch64-neon-syntax – Choose style of NEON code to emit from AArch64 backend:
=generic – Emit generic NEON assembly
=apple – Emit Apple-style NEON assembly
-arch= – architecture(s) from a Mach-O file to dump
-debug-syms – Show all symbols, even debugger only
-defined-only – Show only defined symbols
-dynamic – Display the dynamic symbols instead of normal symbols.
-extern-only – Show only external symbols
-format – Specify output format
=bsd – BSD format
=sysv – System V format
=posix – POSIX.2 format
=darwin – Darwin -m format
-just-symbol-name – Print just the symbol’s name
-m – Alias for –format=darwin
-no-llvm-bc – Disable LLVM bitcode reader
-no-sort – Show symbols in order encountered
-numeric-sort – Sort symbols by address
-print-armap – Print the archive map
-print-file-name – Precede each symbol with the object file it came from
-print-size – Show symbol size instead of address
-radix – Radix (o/d/x) for printing symbol Values
=d – decimal
=o – octal
=x – hexadecimal
-reverse-sort – Sort in reverse order
-rng-seed= – Seed for the random number generator
-s= – Dump only symbols from this segment and section name, Mach-O only
-size-sort – Sort symbols by size
-undefined-only – Show only undefined symbols
-x – Print symbol entry in hex, Mach-O only
-x86-asm-syntax – Choose style of code to emit from X86 backend:
=att – Emit AT&T-style assembly
=intel – Emit Intel-style assembly
[/cc]

17.区分手指触动响应和自动事件响应(如:轮播图,区分手动滑动和timer自动触发)
[cc lang=’c’]
UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
if (pan.delaysTouchesBegan) {
// 这是手动滑动的
}
[/cc]
 

发表回复

电子邮件地址不会被公开。 必填项已用*标注