1、在由NSString生成NSURL对象时,有可能会出现NSString中包含百分号各类括号冒号等对于url来说的非法字符如果直接进行转换的话将得到nil。在对于复杂url进行转换前,可以先试试对待转换的NSString发送 stringByAddingPercentEscapesUsingEncoding: 将其转换为合法的url字符串(其实目的就是保证非法字符用UTF8编码..) 比如这样:
|
|
2、利用代码添加autolayout约束
纯OC代码
- 在storyboard中的一条约束在代码中的体现就是一个约束对象,所以添加在storyboard上添加一条约束,相当于创建了一个约束对象并将该约束对象添加到对应的视图上
- 第一步:创建子控件视图
- 第二步:禁用子控件的autoresizing属性
- 第三步:创建约束对象
- 第四步:添加约束对象
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566- (void)viewDidLoad {[super viewDidLoad];// 1.创建一个子视图,添加到父视图上面UIView *redView = [[UIView alloc] init];redView.backgroundColor = [UIColor redColor];[self.view addSubview:redView];// 2.禁用autoresizing// 2.1给需要设置约束的视图禁用autoresizing,禁用父视图autoresizing对子控件无效//self.view.translatesAutoresizingMaskIntoConstraints = NO;//错误写法redView.translatesAutoresizingMaskIntoConstraints = NO;// 3.添加约束// 3.1红色(红色距离顶部和左边以及右边的边距固定为20,高度固定为50)// 3.1.1顶部(基于父控件)/*constraintWithItem:需要设置约束的viewattribute:需要设置约束的位置relatedBy:约束的条件toItem:约束依赖目标attribute:依赖目标约束位置multiplier:配置系数constant:额外需要添加的长度*//*计算公式:redView.attribute = self.view.attribute * multiplier + constant;其中:=符号取决于relatedBy:参数typedef NS_ENUM(NSInteger, NSLayoutRelation) {NSLayoutRelationLessThanOrEqual = -1, 小于等于NSLayoutRelationEqual = 0, 等于NSLayoutRelationGreaterThanOrEqual = 1, 大于等于};*/// 3.1.1.1创建约束对象NSLayoutConstraint *redTopCos = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:20];// 3.1.1.2判断约束条件的层级关系,并添加到对应的视图[self.view addConstraint:redTopCos];/*attribute:传入的是枚举参数NSLayoutAttributeLeft = 1, 左边距NSLayoutAttributeRight, 右边距NSLayoutAttributeTop, 距离顶部边距NSLayoutAttributeBottom, 距离底部边距NSLayoutAttributeLeading, 左对齐NSLayoutAttributeTrailing, 右对齐NSLayoutAttributeWidth, 宽度NSLayoutAttributeHeight, 高度NSLayoutAttributeCenterX, 中点XNSLayoutAttributeCenterY, 中点YNSLayoutAttributeBaseline, 文本底线对齐*/// 3.1.2左边约束(基于父控件)NSLayoutConstraint *redLeftCos = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];// 3.1.2.2判断约束条件的层级关系,并添加到对应的视图[self.view addConstraint:redLeftCos];// 3.1.3右边约束(基于父控件)NSLayoutConstraint *redRightCos = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];// 3.1.3.2判断约束条件的层级关系,并添加到对应的视图[self.view addConstraint:redRightCos];// 3.1.4 高度约束(自身)NSLayoutConstraint *redHeightCos = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0 constant:50];// 3.1.3.2判断约束条件的层级关系,并添加到对应的视图[redView addConstraint:redHeightCos];}
- VFL语言实现约束的添加
|
|
- -(void)addConstraint:(NSLayoutConstraint *)constraint; 用来将约束添加到view。在添加时唯一要注意的是添加的目标view要遵循以下规则:
- 对于两个同层级view之间的约束关系,添加到他们的父view上
- 对于两个不同层级view之间的约束关系,添加到他们最近的共同父view上
- 对于有层次关系的两个view之间的约束关系,添加到层次较高的父view上
- 对于两个同层级view之间的约束关系,添加到他们的父view上
>
可以通过-setNeedsUpdateConstraints和-layoutIfNeeded两个方法来刷新约束的改变,使UIView重新布局。这和CoreGraphic的-setNeedsDisplay一套东西是一样的~
3、iOS 11实现左长滑删除cell
|
|
4.判断编译器的环境:ARC还是MRC?
|
|
5.类的初始化方法
1.+(void)load
- 当某个类第一次装载到OC运行时系统(内存)时,就会调用
- 程序一启动就会调用
- 程序运行过程中,只会调用1次
2.+(void)initialize
- 当某个类第一次被使用时(比如调用了类的某个方法),就会调用
- 并非程序一启动就会调用
3.在程序运行过程中:1个类中的某个操作,只想执行1次,那么这个操作放到+(void)load方法中最合适