IOS开发

作者: xwlyun | 来源:发表于2015-10-12 17:22 被阅读1589次
  • 重置密码
    http://sc.chinaz.com/info/140328474587.htm

  • CocoaPods第三方库管理
    http://www.360doc.com/content/14/0309/10/11029609_358970353.shtml

  • 布局库
    https://github.com/SnapKit/Masonry

  • 循环引用,无法释放
    self ws

  • 获取设备id
    https://github.com/ylechelle/OpenUDID

  • 用pod添加一个第三方库的步骤
    库的地址:https://github.com/ylechelle/OpenUDID
    终端里输入命令
    用pod搜索,若能搜到就能用pod管理:pod search OpenUDID
    cd到项目的根目录
    pod install --verbose --no-repo-update

  • 使用linq的库
    LinqToObjectiveC

  • dictionary转class的库
    Mantle

  • copy和strong的区别
    @property (nonatomic, strong)
    @property (nonatomic, copy)

  • ios证书
    钥匙串->证书->导出
    .p12文件

  • ios中view自适应键盘的出现,不会出现键盘挡住输入框的情况
    加入第三方库IQKeyboardManager
    pod 'IQKeyboardManager', '~> 3.2.0.3'

  • tableViewCell的自定义
    一般一个页面里就一个tableView,因为多个tableView并不是一起滑动操作的
    一个tableView里分多个块(section)

  • app程序启动上面都有黑底边
    可以设置一下app的launch image,如果实在不需要,那就设置成全黑图片

  • mac上的svn版本管理工具
    cornerstone

  • 证书配置
    新环境开始时,需要用真机测试
    apple developer后台添加了真机uid后
    本地增加.p12证书,xcode选择team,developer后台下载Provisioning Profiles文件
    本地双击了对应的.mobileprovision文件后,项目的Build Settings,Code Signing Identity中要选择一下

  • 收起软键盘
    textView输入时,自动弹出的软键盘,想要点击其他地方就可以收起软键盘
    收起软键盘的方法有:textView resignFirstResponder

  • 截获点击事件的方法有:
    // 声明点击事件 UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)]; [self.view addGestureRecognizer:tapGesture]; // 自定义点击处理 -(void)Actiondo:(id)sender { // 注销当前view(或它下属的text fields)的first responder状态 [self.view endEditing:YES]; }

  • 素材图片的扣取
    打开对应界面的psd,如果宽度640,扣出来的原大小素材图片就是2x大小,再缩小一倍大小就是1x
    找到对应素材位置的图层(要选中那个图层,一般可以通过切换对应图层前面的眼睛图标来回切换是否显示图层来确定是否选择中缺),用选择工具框中,复制到另一个新地方(ctrl+N)
    在新的地方,选择 图像->裁剪,选择透明像素,就可以去除多余的地方
    保存为web用格式

  • NSDictionary初始化
    键值不可以为整数,可以转换成NSNumber

  • ios多线程
    搜gcd

  • 点击事件带坐标
    普通的addTarget,对应的action方法,参数是 (id)sender
    换成
    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)]; [self.btn addGestureRecognizer:tapGesture]; //给自己的btn增加了一个新类型的点击处理事件 -(void)Actiondo:(UITapGestureRecognizer *)sender { CGPoint = [sender locationInView:self.view]; }

  • 手机端调用的api版本
    服务端api,地址中可以带上版本号,以同时满足各版本的请求
    例如:http://www.xxx.com/api/myproject/version7/gettopics.php

  • 绑定的数据刷新
    例如TableView、CollectionView等,可以通过reloadData来刷新数据

  • 显示png出现不透明,例如黄边的问题
    UIImageView设置背景色backgroundColor=[UIColor clearColor]

  • UICollectionView横向cell间距,会出现多10
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; [layout setSectionInset:UIEdgeInsetsMake(0,0,0,0)]; [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; [layout setMinimumInteritemSpacing:3]; // 横向间距 [layout setMinimumLineSpacing:0]; // 只是单行横向也要设置 [layout setItemSize:CGSizeMake(30,30)]; self.collectionView = [[UICollectionVIew alloc] initWithFrame:CGRectMake(0,0,320,40) collectionViewLayout:layout];

  • 获取tableView的偏移量
    self.tableView.contentOffset

  • 单击事件后获取sender
    [self.btn addTarget:self action:@selector(actionClick:) forControlEvents:UIControlEventTouchUpInside]; -(void)actionClick:(id)sender { UIButton *btn = (UIButton*)sender; }

  • 调试看值
    可以鼠标停在变量上,弹出信息
    如果不弹出,可以在下方输出信息框的 蓝色的(lldb)后,输入 po self.array 回车 来打印出self.array的值
    po就是print object的意思

  • 使用gcd多线程获取数据同时更新UI,但UI刷新不及时
    如果使用的不是主线程来获取数据(例如dispatch_async(dispatch_get_global_queue)),那么写在一起的用于更新UI的代码也是在非主线程中的
    所以如果要及时更新UI,在非主线程的调用中,写一个主线程更新UI(dispatch_async(dispatch_get_main_queue))

  • ControllerView之间发送通知
    参数:
    NSDictionary* userInfo = @{@"key1":@"val1"};
    发送:
    [NSNotificationCenter defaultCenter] postNotificationName:@"唯一的通知名" object:nil userInfo:userInfo];
    接收者们:
    [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MyCallBack:) name:@"唯一的通知名" object:nil]; -(void)MyCallBack:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; }

  • 异步网络请求处理方式之一
    无参数时:ASIHTTPRequest
    有参数时:ASIFormDataRequest

  • 系统自带的alertView
    UIAlertView *myAlert = [UIAlertView alloc] initWithTitle:@"这里是提示语" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; [myAlert show]; //实现那个delegate -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // buttonIndex 对应上面的按钮index:0-取消 1-确定 }

  • cell中使用到了sd_setImage结果出现了残影
    问题不在sd_setImage,而是在cell重用时,没有先设置imageView setImage=nil,然后再用sd_setImage

  • 编辑框,编辑时的软键盘弹不出来了
    如果是使用的 [textView becomeFirstResponder],来设置编辑框变成用户输入的第一响应者,来达成弹出软键盘的效果
    需要注意,该textView是否在不经意间被设置成了不可编辑状态(比如键盘类型切换时,文字/表情),使他不能被设置为响应者
    解决办法是注意在上一次软键盘收起的时候,设置textView.editable = YES 还原编辑框的可编辑状态

  • UITapGestureRecognizer 与 tableview collectionView等的选中事件冲突时
    重写UIGestureRecognizerDelegate委托
    可以判断[touch.view class]
    但是如果这个tableView里面的cell使用了自定义的样式里面包好了UIView等等的话,就无法通过view的class来判断了
    可以给self.view这个背景view添加一个tag,然后判断touch.view.tag是否是这个tag就可以判断出来了

  • UIView动画
    [UIView beginAnimations:nil context:nil]; // 开始动画 [UIView setAnimationDuration:10.0]; // 动画时长 CGPoint point = _imageView.center; point.y += 150; // 向下移动 [_imageView setCenter:point]; [UIView commitAnimations]; // 提交动画

  • cell里使用Masonry布局库布局,mas_makeConstraints没有生效或受影响
    可能是cell复用时,make没有生效的原因
    解决办法是改用mas_remakeConstraints

  • 使用Masonry布局后,使用UIView animation来做动画,发现动画不自然(控件从四周聚集起来的样子),或没有生效
    因为autolayout和动画有冲突,需要我们手动的立即刷新一下控件的位置(在动画前,在动画结束后,各刷新一下)
    WS(ws); // 起始位置 [self.backVIew mas_remakeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(ws.mas_bottom).with.offset(0); make.left.equalTo(ws.mas_left).with.offset(0); make.right.equalTo(ws.mas_right).with.offset(0); }]; // 动画前立即刷新一下 [self.backView setNeedsLayout]; [self.backView layoutIfNeeded]; // 动画 [UIView animateWithDuration:0.5f animations:^{ [self.backView mas_updateConstraints:^(MASConstraintMaker *make){ make.top.equalTo(ws.mas_bottom).with.offset(-300); // 注意这里只能对在起始位置设置过的属性进行修改 }]; // 动画后立即刷新一下 [self.backView setNeedsLayout]; [self.backView layoutIfNeeded]; }];

  • 隐藏顶部栏StatusBar
    一般使用 [[UIApplication sharedApplication] setStatusBarHidden:YES]; 即可
    还一种方法,是修改当前window的级别 self.window.windowLevel = UIWindowLevelStatusBar;
    LevelStatusBar要大于LevelNormal,所以会显示在上面

  • 服务端返回json,app解析出来的emoji表情出现了问题
    app解析json,有下面两种方式
    // 方式1(这种方式解析出来的emoji可能会出现问题) NSData *data = [request responseData]; // (ASIHTTPRequest *)request NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSDictionary *dic = [str JSONValue]; // 方式2(这样的解析在某些时候可以替代方式1) NSData *data = [request responseData]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

  • UIButton同时设置图片和文字
    btn setImage
    btn setTitle
    间距:btn setTitleEdgeInsets(文字)

  • UITableView style
    UITableViewStylePlain:
    section header会固定;
    heightForHeaderInSection设置0有效;
    UITableVIewStyleGrouped:
    section header不会固定;
    heightForHeaderInSection设置0无效;

  • 获取app版本号
    NSBundle *bundle = [NSBundle bundleForClass:[self class]]; [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; // 4.9.2 [bundle objectForInfoDictionaryKey:@"CFBundleVerion"]; // 16

  • cell中的btn点击后,获取点击到的是哪个cell
    -(void)btnClick:(id)sender { CGPoint btnPosition = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:btnPosition]; }

  • ios中获取时间戳
    long nowTime = [[NSDate date] timeIntervalSince1970];

  • app从后台返回来时执行的函数
    appdelegate中的 -(void)applicationDidBecomeActive:(UIApplication *)application{}

  • 设置圆角不生效
    UIView.layer.cornerRedius = 12; // 设置了圆角度数
    UIView.layer.masksToBounds = YES; // 这里要设置一下

  • tableview插入新row时的动画效果
    [itmes addObject:new_row]; // 如果你是用一个items数组来存放所有row的数据的话 [tableView setContentSize:CGSizeMake(tableView.contentSize.width,tableView.contentSize.height+row_height)] // 为新row增加显示的空间 [tableView beginUpdates]; [tableView insertRowsAtIndexPaths:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationNone]; // 插入新row [tableView endUpdates]; [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[items count]-1 inSection:0 atScrollPosition:UITableViewScrollPositionNona animated:NO]] // 定位到

  • 单个controller可以注册监听app从后台返回来的事件
    [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myfunc) name:UIApplicationWillEnterForegroundNotification object:nil];

  • 用户标识之一
    \#define IDFA [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]

  • 判断是否安装了某应用,是否打开它
    NSURL *appSchemeUrl = [NSURL URLWithString:@"yourapp://"];if ([[UIApplication sharedApplication] canOpenURL:appSchemeUrl]) { [[UIApplication sharedApplication] openURL:appSchemeUrl]; }else{ NSURL *appStoreUrl = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/yourid"]; if ([[UIApplication sharedApplication] canOpenURL:appStoreUrl]) { [[UIApplication sharedApplication] openURL:appStoreUrl]; } }

  • 单例的使用
    User.h: @interface User:NSObject +(User*)shareInstance; @end User.m: static id _instance; @implementation User +(User*)shareInstance { static dispatch_once_t once; dispatch_once(&once,^{_instance = [[self alloc] init];}); return _instance; } @end 调用的时候: [User shareInstance];

  • [NSUserDefaults standarUserDefaults] setObject setValue不能放long之类的数值
    用[NSNumber numberWithLong]之类的,用NSNumber包装一下

  • NSString 转成 int,0的转换会有问题
    [@"0" intValue] = nil

  • 监控手势操作
    UISwipeGestureRecognizer *recognizer = [UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; recognizer.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:recognizer]; -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{ if(recognizer.direction == UISwipeGestureRecognizerDirectionRight) { [self back]; // 这个例子是右滑手势的返回功能 } } -(void)back{ [self.nacigationController popViewControllerAnimated:YES]; }

  • 自定义Framework
    可打出模拟器专用framework,真机专用framework
    要打出通用性的framework,需要合并两个framework
    可以在自定义framework项目中,添加Run Script,每次Run时执行一个脚本来自动生成
    if [ "${ACTION}" = "build" ]thenINSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.frameworkDEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.frameworkSIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.frameworkif [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"#ditto "${DEVICE_DIR}/Headers" "${INSTALL_DIR}/Headers"lipo -create "${DEVICE_DIR}/${PROJECT_NAME}" "${SIMULATOR_DIR}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}"#open "${DEVICE_DIR}"#open "${SRCROOT}/Products"fi

相关文章

  • iOS开发优秀博客和软件推荐

    iOSBlogAndTools iOS开发优秀博客和软件推荐 iOS开发中文博客 iOS开发工具 iOS开发网站 ...

  • 收录 : iOS支付开发

    iOS 银联支付开发流程iOS 微信支付开发流程iOS 支付宝支付开发流程iOS Apple Pay开发流程App...

  • IOS开发问题索引(四)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(八)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(七)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(六)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(五)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(九)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(二)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(三)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

网友评论

  • 星光伴我行:哇哦,不错的文章
  • ekg:collectionView cell点击与键盘处理冲突,你是怎么解决的呢,通过[touch.view class]只能判断出tableView,判断不了 collectionView,求解答,谢谢

本文标题:IOS开发

本文链接:https://www.haomeiwen.com/subject/inlocttx.html