您的位置:首页 > 移动开发 > IOS开发

iOS开发笔记(一)

2016-05-31 22:40 609 查看
   这是本人在开发中简单整理的iOS笔记,有点凌乱吧  哈哈。不过内容简单易懂  希望你能喜欢。





1、内存
内存溢出:内存不够用,数据溢出
内存泄漏:该释放的对象没有释放

2、性能检测方法
静态分析:product—>Analyze
动态分析:product—>profile

3、多线程安全解决方法和线程控制
 >只在主线程刷新UI界面
 >防止资源抢夺 使用synchronize加锁
 >异步操作 尽量使用GCD

4、iOS应用数据存储的常用方式
 >属性列表归档(plist)
 >偏好设置(NSUserDefault)
 >NSKeyedArchiver或NSKeyedUnArchiver<NSCoding>
 >SQlite3(第三方FMDB)
 >CoreData

5、默认情况 模拟器的目录是隐藏的,要想显示出来,需要在mac终端输入下面指令:
   显示mac隐藏文件的指令:defaults write com.apple.finder AppleShowAllFiles YES
  隐藏mac隐藏文件的指令: defaults write com.apple.finder AppleShowAllFiles NO
  最后还要强制退出 重新启动finder

6、定时器
NSTimer:一般用于定时更新非界面的数据 如歌词进度 歌曲播放进度等
CADisplayLink:适用刷一帧界面,默认每秒60次

>NSTime用法
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector() userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:self.currentTimeTimer forMode:NSRunLoopCommonModes];
> CADisplayLink用法
self.timer = [CADisplayLink displayLinkWithTarget:self selector:@selector()];
 [self.timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

7、设置View.layer阴影的要素
 > 设置颜色shallowColor
 > 设置偏移位shallowOffset
 > 设置透明度shallowOpaCity 
 
8、判断设备系统的版本号
[[UIDevice currentDevice].systemVersion doubleValue]

9、如果想要删除UITableViewCell里的cell的删除,手指在cell上面测滑实现删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

10、iOS中的事件可分三大类型
> 触摸事件
> 加速计事件
> 远程控制事件
另外事件的产生和传递:触摸事件的传递是从父控件传递到子控件,如果父控件不能接收触摸事件,那么子控件就不可能接收到触摸事件
事件传递是从父控件传递到子控件:UIApplication—>UIWindow—>合适的子控件

11、图片下载方式imageWithcontentsOfFile:和imageNamed:的区别
> imageWithcontentsOfFile:这个方法加载的图片不会有缓存,适用适合用来加载大图片、一次性的图片(使用频率较低)
> imageNamed:这个方法加载的图片有缓存、适合用来加载小图片、使用频率比较高的图片
另外小图片建议应该放在Images.xcassets中;大图片建议放在Supporting Files中  

12、给navigation bar设置title颜色
    UIColor *orange = [UIColor orangeColor];
    NSDictionary *dict = [NSDictionary dictionaryWithObject:orange forKey:NSForegroundColorAttributeName];
    [self.navigationController.navigationBar setTitleTextAttributes:dict];
13、KVC修改textField的placehold的字体颜色、大小
    self.textField.placeholder = @"i am moti";
    [self.textField setValue:[UIColor orangeColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.textField setValue:[UIFont boldSystemFontOfSize:17] forKeyPath:@"_placeholderLabel.font”];

14、收键盘(结束编辑界面)
>[self.view endEditing:YES]
>[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

15、第三方框架FMDB报错  "_sqlite3_bind_blob", referenced from:
      -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
必须导入sqlite3.dylib到framwork中

16、修改statusbar文字颜色
在iOS7以上状态栏的字体颜色默认是黑的 如果想要改变其字体颜色 必须现在项目的info.plist添加并设置View controller-based status bar appearance ,然后可以在appDelegate中添加代码:[application setStatusBarStyle:UIStatusBarStyleLightContent];  状态栏的样式有两个是过期的
    UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0,7_0,"Use UIStatusBarStyleLightContent") =1,

    UIStatusBarStyleBlackOpaque      NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
17、iOS运行时想要隐藏status bar
要隐藏status bar必须在info.plist中添加Status bar is initially hidden 并设置为YES属性
如果有什么可以值得探讨的 欢迎一起交流:

如果有什么好的建议,请联系虾米,虾米感激不尽 蟹蟹 哈!!




虾米联系方式:

QQ:584837022

github:https://github.com/ios-cjh
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息