2018-02-05(容易遗忘基础技术点)

2018-02-08  本文已影响19人  Xcode8
1-1、实用快捷键
以前使用的VVDucments在Xcode更新之后,不好用,但是现在xcode内部集成了注释的插件,在default的默认情况下,快捷键"option+command+/"()。需要更改快捷键的设置Xcode-Preference-Key Bindings里面的Add Documenttation可以进行修改快捷键的设置。
1、切换头文件和m.文件,很实用
    Command + control+ 上下箭头键
2、代码缩进
    左缩进 command+[
    右缩进 command+]
    代码上移:command +option+[
    代码下移:command +option+]
3、代码选中
    选中取消单词代码:option+shift+左右箭头
    选中取消行代码:  option+shift+上下箭头
4、为Xcode添加删除行、复制行快捷键:  参考资料[http://blog.csdn.net/biggercoffee/article/details/50513899]
5.command+alt+// 方法注释
1-2、git基本使用
  1.cd +file
  2.git init     git status
  3.git add .
  4.git commit -m "注释" 
  与远程的仓库相连:
  5.git remote add origin https://github.com/jinweicheng/test.git
  6.git push origin master
  添加tag标签
  7.git tag -a '1.0.0' -m '打标签' //添加tag
  8.git tag  //查看tag状态
  9.git push --tags   //提交所有的tags
  10.git tag '2.0.0' //代码修改之后再次添加的tag
  11.git push origin '2.0.0'  //提交新tag的代码
  删除tag
  12.git tag -d '2.0.0'  //删除本地的tag
  13.git push origin :2.0.0  //删除远程代码库的tag 
1-2-1、git版本控制
注意:使用Xcode自带的git功能,需要首先配置一下公钥和私钥   ssh文件配置;生成的公钥和私钥,公钥发给公司的服务器人员,私钥自己保存,公钥和私钥用来保证,git数据处理的时候,保证传输的过程是安全的!自己犯的错误(生成私钥的信息里面要有邮箱号码(可以打开私钥查看是否正确),而不是用户信息)。
 1、拉取工程: git clone ssh://git@地址(不带http)
 2、拉取工程之后工程有修改处理:使用Xcode自带的git  
    1)commit项目,添加注释   "项目修改的注释";
    2)pull  ,将服务器的代码拉取到本地;
    3)push,将自己修改的项目提交到公司的服务器上面;
1-2-2、命令行
2-2-1 :配置git user信息
git config --list         //查看user信息
git config --global user.name “cjw”
git config --global user.email "452919194@qq.com"
2-2-2:获取用户的主路径命令行:pwd
2-2-3公司仓库拉不下来(公钥出现问题):如下图所示
:Volumes:Mac磁盘:证书配置:公司仓库证书:公钥问题.jpg
1-3、svn纯命令行
常见命令:
  svn checkout服务器地址 —username=zs —password=zs 
  svn update 
  svn commit 
  svn status 
  svn log 
实战svn:
1. 进入工程目录   cd /目录文件路径
2. svn status:查看修改的代码状态;svn update :更新服务器代码
3.svn commit -m "注释部分" 

注意:commit提交的注释文字必须要大于8个字

2.1 问题处理
遇到问题:conflict因为修改同一文件造成;
解决方法:tc(使用服务器的版本替换掉本地的版本,注意在使用该命令之前注意备份);
1-4、修改hosts
1. 进入hosts的目录   cd /etc
2. 打开hosts文件  sudo vi hosts
3. 使用vi的编辑命令,如:i
4. 保存的时候需要切换到非编辑状态,按键盘上的esc键
5. 输入:x就保存了,如果不保存使用:wq!
1-5、cocopad基本使用
1.cd +文件目录
2.pod init                 创建了Podfile文件,在这个文件里面进行添加第三方库的信息
3.pod search MJExtension   搜索第三方库

现在的格式:
  # platform :ios, '9.0'
     target 'test' do
     use_frameworks!
     pod 'MJExtension'
   end

4.pod install          按照podfile文件的描述进行安装

注意:vim Podfile 进入文本编辑     i编辑   esc退出   切换:wq保存退出   pod install即可
一、iOS基础注意事项
0.Objective-C 语言的缺陷:

1.Objective-C中swich case语句只能之别基本数据类型:整型、字符型和枚举类型,有时对于后台返回的数据字符串,处理不方便;
2.Objective-C中不支持多重继承:一个object不能即继承objectA,又继承objectB;(想要实现类似的功能,可以采用的protol的方式)
3.Objective-C中不支持命名空间namespace(多个框架里面的方法、属性比较类似),所以在使用的时候可以通过添加前缀来进行区分;

1.2018-02-05 单击双击冲突处理

第一种解决方法:(意思是当单击手势识别失败的时候,双击手势将替换掉单击手势------会产生冲突,触发是很随机的,如果我们想设置一下当手势互斥时要优先触发的手势,使用如下的方法设置优先触发:) [singleC requireGestureRecognizerToFail:doubleC];

//测试区分单击和双击--- 出现的问题处理,双击的时候还会触发单击的事件,事件需要单独分离开
_touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, KWidth, KHeight-100)];
_touchView.backgroundColor = [UIColor redColor];
[self.view addSubview:_touchView];
//添加单击、双击事件
UITapGestureRecognizer *singleC = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleC:)];
singleC.numberOfTapsRequired = 1;
[_touchView addGestureRecognizer:singleC];

UITapGestureRecognizer *doubleC = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleC:)];
doubleC.numberOfTapsRequired = 2;
//第一种解决方法(意思是当单击手势识别失败的时候,双击手势将替换掉单击手势)
[singleC requireGestureRecognizerToFail:doubleC];
[_touchView addGestureRecognizer:doubleC];

#pragma mark - 单击事件
- (void)singleC:(UITapGestureRecognizer *)singleC{
    NSLog(@"SINGLE-CLICK"); 
}
#pragma mark - 双击事件
- (void)doubleC:(UITapGestureRecognizer *)doubleC{
    NSLog(@"DOUBLE-CLICK");
}
2.注意:UIImageView当中Image并不是直接添加在层上面的.这是添加在layer当中的contents(子层)里.
3.理解layer的二个属性position、anchorPosition

3-1、UIView的frame、bounds、center属性:

frame(参考系父控件):相对于父控件的frame,(x、y为到父视图原点的位置);
bounds(参考系自身):x、y值为0的frame(x、y为到自身原点的位置);
center(参考父视图):当前控件的中心位置位于父控件位置;

3-2、layer的frame、bounds、position、anchorPosition:

frame、bounds与view层的一致;
position(参考父控件):它是用来设置当前视图的在父控件的位置,不设置position值得话 --默认值为(0,0);
anchorPosition(参考自身):默认值为(0.5,0.5),取值范围为(0,0)自身的左上角到(1,1)自身的右下角;

3-3代码测试:

//测试anchorPosition(position保持不变)
    CALayer *layer11 = [CALayer layer];
    layer11.bounds = CGRectMake(0, 0, 100, 100);//设置自身的size
    layer11.anchorPoint = CGPointMake(0, 0);
    layer11.position = CGPointMake(100, 100);
    layer11.backgroundColor = [UIColor yellowColor].CGColor;
    [self.view.layer addSublayer:layer11];

    CALayer *layer12 = [CALayer layer];
    layer12.bounds = CGRectMake(0, 0, 100, 100);
    layer12.anchorPoint = CGPointMake(0.5, 0.5);
    layer12.position = CGPointMake(100, 100);
    layer12.backgroundColor = [UIColor greenColor].CGColor;
    [self.view.layer addSublayer:layer12];

    CALayer *layer13 = [CALayer layer];
    layer13.bounds = CGRectMake(0, 0, 100, 100);
    layer13.anchorPoint = CGPointMake(1, 1);
    layer13.position = CGPointMake(100, 100);
    layer13.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:layer13];


//测试position(anchorPosition保持不变)
    CALayer *layer21 = [CALayer layer];
    layer21.bounds = CGRectMake(0, 0, 100, 100);//设置自身的size
    layer21.anchorPoint = CGPointMake(0.5, 0.5);
    layer21.position = CGPointMake(100, 300);
    layer21.backgroundColor = [UIColor yellowColor].CGColor;
    [self.view.layer addSublayer:layer21];

    CALayer *layer22 = [CALayer layer];
    layer22.bounds = CGRectMake(0, 0, 100, 100);
    layer22.anchorPoint = CGPointMake(0.5, 0.5);
    layer22.position = CGPointMake(200, 300);
    layer22.backgroundColor = [UIColor greenColor].CGColor;
    [self.view.layer addSublayer:layer22];

    CALayer *layer23 = [CALayer layer];
    layer23.bounds = CGRectMake(0, 0, 100, 100);
    layer23.anchorPoint = CGPointMake(0.5, 0.5);
    layer23.position = CGPointMake(300, 300);
    layer23.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:layer23];

效果图:


position与anchorPosition.jpg
总结:layer在父layer中的位置,是有position和anchorPosition共同决定;
4.内存管理

1.内存基础:

1-1、内存几大分区参考资料http://blog.csdn.net/yang198907/article/details/50212925

1-2、OC对象(通过alloc、new、copy、nsmutablecopy、都需要release,autorealse );OC基本数据类型(整型Int NSInteger、字符型char、浮点型float double、布尔型Bool、枚举型enum、结构体struct)。OC对象在使用的过程中需要管理内存,而非OC对象在栈中,不需要管理内存。

1-3、野指针、空指针(野指针是已经释放的内存对象、空指针,区别是访问野指针崩溃、空指针不做任何事情),所以安全的做法是:在dealloc方法里面realse后将指针置空;参考https://www.jianshu.com/p/7d73654ed91a

2.Apple设备的单个应用程序的crash的内存参考料资料:https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget`

device: (crash amount/total amount/percentage of total)
iPad1: 127MB/256MB/49%
iPad2: 275MB/512MB/53%
iPad3: 645MB/1024MB/62%
iPad4: 585MB/1024MB/57% (iOS 8.1)
iPad Mini 1st Generation: 297MB/512MB/58%
iPad Mini retina: 696MB/1024MB/68% (iOS 7.1)
iPad Air: 697MB/1024MB/68%
iPad Air 2: 1383MB/2048MB/68% (iOS 10.2.1)
iPad Pro 9.7": 1395MB/1971MB/71% (iOS 10.0.2 (14A456))
iPad Pro 10.5”: 3057/4000/76% (iOS 11 beta4)
iPad Pro 12.9” (2015): 3058/3999/76% (iOS 11.2.1)
iPad Pro 12.9” (2017): 3057/3974/77% (iOS 11 beta4)
iPod touch 4th gen: 130MB/256MB/51% (iOS 6.1.1)
iPod touch 5th gen: 286MB/512MB/56% (iOS 7.0)
iPhone4: 325MB/512MB/63%
iPhone4s: 286MB/512MB/56%
iPhone5: 645MB/1024MB/62%
iPhone5s: 646MB/1024MB/63%
iPhone6: 645MB/1024MB/62% (iOS 8.x)
iPhone6+: 645MB/1024MB/62% (iOS 8.x)
iPhone6s: 1396MB/2048MB/68% (iOS 9.2)
iPhone6s+: 1392MB/2048MB/68% (iOS 10.2.1)
iPhoneSE: 1395MB/2048MB/69% (iOS 9.3)
iPhone7: 1395/2048MB/68% (iOS 10.2)
iPhone7+: 2040MB/3072MB/66% (iOS 10.2.1)
iPhone X: 1392/2785/50% (iOS 11.2.1)

3.iPhone手机的运行内存信息:

u=3195029165,3097737581&fm=173&s=FDB03E9D1BDB404904D4107203007070&w=640&h=298&img.JPEG

4.内存管理的意义:如1、2项所示apple设备本身的运行内存有限、每个应用程序的单独的运行最大的内存也有特定的限制,基于此认知,我们在进行代码书写的过程中需要多加注意内存管理。(当应用程序运行过程中所占用的内存较大时,便会收到系统给出的内存警告,如果应用程序所占用的内存超过限制时,便会被系统强制关闭)
5.常见产生内存的问题分析参考资料:http://blog.csdn.net/clovejq/article/details/71107674

1.代理产生的内存的问题:tableView添加addSubView到VC的self.view上面,此时VC强引用tableView,使用tableView的一些delegate、dataSource展示出效果图,需要先设置tableView.delegate = self,此时为了避免tableView强引用self使用weak修饰可以避免循环引用;


delegate问题处理.png

系统UITableView的处理方式:
@property (nonatomic, weak, nullable) id <UITableViewDelegate> delegate;
@property (nonatomic, weak, nullable) id <UITableViewDataSource> dataSource;

2.NSTimer在不使用的时候需要:(注意在dealloc方法里面需要同样的处理)
[_timer invalidate];
_timer = nil;

3.block产生循环引用:
1)._collectionView.mj_footer :当前控制器强引用MJRefreshFooter对象(mj_footer属于mj_footer的对象属性);
2).mj_footer里面包含self的话造成相互强引用;
3).解决方案如下:(1、2点)

//1.__weak为了(MJRefreshFooter对象弱引用当前self对象);
__weak typeof(self) weakSelf = self;
_collectionView.mj_footer = [MJRefreshBackNormalFooter  footerWithRefreshingBlock:^{
//2.__strong修饰目的:weak修饰的对象生命周期比较短暂(可能还没有用到就已经释放了,概率虽然比较低,但是得考虑这种情况)
    __strong typeof(weakSelf) strongSelf = weakSelf;
    strongSelf->_index ++;
    [strongSelf loadData];
}];

+ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock
{
    MJRefreshFooter *cmp = [[self alloc] init];
    //cmp属于MJRefreshFooter,refreshingBlock如果这里面带有未做处理的self,则会造成循环引用问题;
    cmp.refreshingBlock = refreshingBlock;
    return cmp;
}

4.使用autorelease pool:该循环内产生大量的临时对象,直至循环结束才释放,可能导致内存泄漏,解决方法为在循环中创建自己的autoReleasePool,及时释放占用内存大的临时变量,减少内存占用峰值。参考资料http://blog.csdn.net/z040145/article/details/69398768

for (int i = 0; i < 100000; i++) {
    NSString *string = @"Abc";
    string = [string lowercaseString];
    string = [string stringByAppendingString:@"xyz"];
    NSLog(@"%@", string);
}改为
for (int i = 0; i < 100000; i++) {
    @autoreleasepool {
        NSString *string = @"Abc";
        string = [string lowercaseString];
        string = [string stringByAppendingString:@"xyz"];
        NSLog(@"%@", string);
    }
}

参考书籍资料:iOS与OSX多线程和内存管理

1.取得对象的存在(内存中开辟了对象的空间)和持有对象(指针指向);
2.对于alloc、new、copy、mutableCopy方法生成并持有的对象、或者使用retain方法持有的对象,在不需要使用的时候及时释放release;
5.深究block

5.1、blcok截获的自动变量:

int count = 10;
    void (^block2)(void) = ^{
        NSLog(@"count = %d",count);
    };
count = 20;
block2();
打印结果:count = 10

分析:block表达式保存了的自动变量的瞬间值,所以在执行block表达式后面修改count的值,不会改变的block代码块里面的保存的count的值;

5.2、block的常见知识:

在block里面无法修改变量的值,除非在block表达式的外面使用的__block修饰;
1.重点注意事项
id array = [NSMutableArray array];
    void (^block)(void) = ^{
        id model = [[NSObject alloc] init];
        [array addObject:model];
        NSLog(@"array = %@",array);
    }; 
block();
编译没有问题:书籍上面的解释(调用了变更对象的方法,并没有进行赋值操作)
2.正常的__block的问题
id array1 = [NSMutableArray array];
    void (^block1)(void) = ^{
        array1  = [NSMutableArray array];
    };
block1();
编译出错:因为对象变量进行了重新赋值操作;
3.block中C语言数组的问题(指针的问题)
const char text1[] = "hello1";
void (^blk4)(void) = ^{
    NSLog(@"bck4====%c",text1[2]);
};
blk4();
编译报错:Cannot refer to declaration with an array type inside block(使用C语言的字面量字符数组,截获自动变量的方法没有办法截获C语言数组的值);
解决方案如下:
const char *text2 = "hello2";
void (^blk5)(void) = ^{
    NSLog(@"blk5==%c",text2[3]);
};
blk5();
编译通过:直接使用指针的方式即可正确的截获的自动变量的值

待更新!!!

6.SDK开发学习

参考资料:http://www.sohu.com/a/167662512_208051 https://www.cnblogs.com/richard-youth/p/7746223.html

7.哈希算法

参考资料1.http://blog.csdn.net/asdzheng/article/details/70226007

8.基本知识

8-1、iOS开发的类目和延展基础:
https://www.cnblogs.com/stevenwuzheng/p/8205321.html
拓展:http://blog.csdn.net/u012078168/article/details/72758337

8-2、配置字典:

NSDictionary* msg = @{
                      @"saleMoney":self.dataModel.saleMoney,
                      @"productId":@(self.dataModel.productID.integerValue)
                      };
9.iOS开发的基础
iPhone 4/4s           320*480       3.5寸        比例4:3
iPhone 5/5s/SE        320*568       4寸          比例16:9
iPhone 6/6s           375*667       4.7寸        比例16:9
iPhone 6p             414*736       5.5寸        比例16:9
iPhone 7              375*667       4.7英寸      1334x750像素 
iPhone7p              414*736       5.5英寸      1920x1080像素  
iPhone 8              375*667      4.7英寸        1334×750像素 
iPhone 8 Plus         414*736       5.5英寸       16:9
iPhone X              375*812      5.8英寸        2436×1125(屏幕纵横比接近13:6)
iPhone XS            375*812      5.8英寸        2436 x 1125
iPhone XR           414*896       6.1英寸        1792×828
iPhone XS Max   414* 896      6.5英寸        2688 x 1242   
WX20170914-174914@2x.png

1.屏幕尺寸相关变化 -- tabbar 49 高度增加了145pt,变成812pt. 屏幕圆角显示,注意至少留10pt边距。 状态栏高度由20pt变成44pt,留意这个距离就能避开“刘海”的尴尬,相应的导航栏以上变化64->88。 底部工具栏需要为home indicator留出34pt边距。 物理分辨率为1125px * 2436px(375*812).

10.终端地址

IP:127.0.0.1(localHost本机地址);
查看IP地址:www.ip138.com;
终端:ping+地址(测试网络地址);

11.郭曜源博客YYKit:https://blog.ibireme.com学习中

博客学习:https://github.com/tangqiaoboy/iOSBlogCN

12、埋点数据统计sdk

学习地址:https://www.jianshu.com/p/5f16e1de6d5a

13、证书问题

1.无法导出p12文件:

证书问题.jpg

问题分析: 1)左侧有两个分类,一个是钥匙串,一个是种类,要选择种类中的我的证书或者证书。然后在右侧证书列表中,右键导出即可; 2)使用钥匙串生成的证书有问题,格式为(certSigningRequest) 比如这个证书是从其他电脑拷贝过来的,那么这个证书是不能用的,必须使用本机生成的才能用(自己遇到的问题就是这个);3)可能是Mac系统缺少AppleWWDRCA.cer证书(Apple World Wide Developer Relations Certification Authority)

上一篇下一篇

猜你喜欢

热点阅读