提高iOS开发的小技巧和思路小结 (二)

2020-01-20 12:51:02刘景俊

三、如何合理的去将项目繁琐的文件去分类好

这个我本来是想分享我自己的一个项目文件夹分类,但是我找到一个更好的是基于MVC,规范化项目文件确实能省下不少事情。截图给大家看看吧。而且该框架包含了不少常用的功能,给大家参考下吧。

强烈推荐

github地址:https://www.easck.com/p>

ios开发技巧,ios开发实用技巧,ios,开发小技巧

b.各种扩展

ios开发技巧,ios开发实用技巧,ios,开发小技巧

c.资源,以及一些配置

ios开发技巧,ios开发实用技巧,ios,开发小技巧

这个框架确实让我受益匪浅,大家也可以去学习学习。

四、切圆角,不要去使用clipsToBounds,这种耗费性能的操作

相信有很多人切圆角的时候会采用下面的这种方式,这种方式会触发离屏渲染,这种渲染方式非常消耗性能


 self.tableView.cornerRadius = 10;
 [self.tableView clipsToBounds];

请采用下面这种方式


UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.evaluateView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(10, 10)];
 CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
 maskLayer.frame = self.evaluateView.bounds;
 maskLayer.path = maskPath.CGPath;
 self.evaluateView.layer.mask = maskLayer;

下面补充一下只想切固定几个圆角的方案,UIRectCornerBottomLeft | UIRectCornerBottomRight 这样的枚举就是针对左上角和右上角的角进行切割


UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.darkView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)]; 
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame = self.darkView.bounds; 
maskLayer.path = maskPath.CGPath;
self.darkView.layer.mask = maskLayer;

五、响应者链,来解决多层级直接的页面传值

使用场景,自定义一个view的时候和父控制器隔了几层,需要刷新或者对父控制器做出一些列修改,这时候可以使用响应者连直接拿到父控制器,避免使用多重block嵌套或者通知这种情况


- (UIViewController *)viewController {
 for (UIView* next = [self superview]; next; next = next.superview) {
 UIResponder *nextResponder = [next nextResponder];
 if ([nextResponder isKindOfClass:[UIViewController class]]) {
 return (UIViewController *)nextResponder;
 }
 }
 return nil;
}