diff --git "a/OC\344\273\243\347\240\201\350\247\204\350\214\203\346\200\273\347\273\223.md" "b/OC\344\273\243\347\240\201\350\247\204\350\214\203\346\200\273\347\273\223.md" index 7f6486e..f02dc13 100755 --- "a/OC\344\273\243\347\240\201\350\247\204\350\214\203\346\200\273\347\273\223.md" +++ "b/OC\344\273\243\347\240\201\350\247\204\350\214\203\346\200\273\347\273\223.md" @@ -4,7 +4,7 @@ Objective-C编码规范,内容来自苹果、谷歌的文档翻译,[『博 转载请注明出处。 -##概要 +## 概要 Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和Mac应用程序。关于Objective-C的编码规范,苹果和谷歌都已经有很好的总结: @@ -14,17 +14,17 @@ Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和 本文主要整合了对上述文档的翻译、作者自己的编程经验和其他的相关资料,为公司总结出一份通用的编码规范。 -##代码格式 +## 代码格式 -###使用空格而不是制表符Tab +### 使用空格而不是制表符Tab 不要在工程里使用Tab键,使用空格来进行缩进。在`Xcode > Preferences > Text Editing`将Tab和自动缩进都设置为**4**个空格。(_Google的标准是使用两个空格来缩进,但这里还是推荐使用Xcode默认的设置。_) -###每一行的最大长度 +### 每一行的最大长度 同样的,在`Xcode > Preferences > Text Editing > Page guide at column:`中将最大行长设置为**80**,过长的一行代码将会导致可读性问题。 -###函数的书写 +### 函数的书写 一个典型的Objective-C函数应该是这样的: @@ -62,7 +62,7 @@ Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和 ... } ``` -###函数调用 +### 函数调用 函数调用的格式和书写差不多,可以按照函数的长短来选择写在一行或者分成多行: @@ -97,7 +97,7 @@ Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和 error:arg3]; ``` -###@public和@private标记符 +### @public和@private标记符 @public和@private标记符应该以**一个空格**来进行缩进: @@ -111,7 +111,7 @@ Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和 @end ``` -###协议(Protocols) +### 协议(Protocols) 在书写协议的时候注意用`<>`括起来的协议和类型名之间是没有空格的,比如`IPCConnectHandler()`,这个规则适用所有书写协议的地方,包括函数声明、类声明、实例变量等等: @@ -125,7 +125,7 @@ Objective-C是一门面向对象的动态编程语言,主要用于编写iOS和 @end ``` -###闭包(Blocks) +### 闭包(Blocks) 根据block的长度,有不同的书写规则: @@ -189,7 +189,7 @@ void (^largeBlock)(void) = ^{ }]; ``` -###数据结构的语法糖 +### 数据结构的语法糖 应该使用可读性更好的语法糖来构造`NSArray`,`NSDictionary`等数据结构,避免使用冗长的`alloc`,`init`方法。 @@ -253,11 +253,11 @@ NSDictionary *stillWrong = @{ }; ``` -##命名规范 +## 命名规范 -###基本原则 +### 基本原则 -####清晰 +#### 清晰 命名应该尽可能的清晰和简洁,但在Objective-C中,清晰比简洁更重要。由于Xcode强大的自动补全功能,我们不必担心名称过长的问题。 @@ -310,11 +310,11 @@ sendPort displayName ``` -####一致性 +#### 一致性 整个工程的命名风格要保持一致性,最好和苹果SDK的代码保持统一。不同类中完成相似功能的方法应该叫一样的名字,比如我们总是用`count`来返回集合的个数,不能在A类中使用`count`而在B类中使用`getNumber`。 -###使用前缀 +### 使用前缀 如果代码需要打包成Framework给别的工程使用,或者工程项目非常庞大,需要拆分成不同的模块,使用命名前缀是非常有用的。 @@ -324,7 +324,7 @@ displayName - 命名前缀的时候不要和苹果SDK框架冲突。 -###命名类和协议(Class&Protocol) +### 命名类和协议(Class&Protocol) 类名以大写字母开头,应该包含一个*名词*来表示它代表的对象类型,同时可以加上必要的前缀,比如`NSString`, `NSDate`, `NSScanner`, `NSApplication`等等。 @@ -332,7 +332,7 @@ displayName 有些协议本身包含了很多不相关的功能,主要用来为某一特定类服务,这时候可以直接用类名来命名这个协议,比如`NSObject`协议,它包含了id对象在生存周期内的一系列方法。 -###命名头文件(Headers) +### 命名头文件(Headers) 源码的头文件名应该清晰地暗示它的功能和包含的内容: @@ -344,7 +344,7 @@ displayName - Framework中有时候会实现在别的框架中类的类别扩展,这样的文件通常使用`被扩展的框架名`+`Additions`的方式来命名,比如`NSBundleAdditions.h`。 -###命名方法(Methods) +### 命名方法(Methods) Objective-C的方法名通常都比较长,这是为了让程序有更好地可读性,按苹果的说法*“好的方法名应当可以以一个句子的形式朗读出来”*。 @@ -424,7 +424,7 @@ Objective-C的方法名通常都比较长,这是为了让程序有更好地可 ...title:(NSString *)aString ``` -###存取方法(Accessor Methods) +### 存取方法(Accessor Methods) 存取方法是指用来获取和设置类属性值的方法,属性的不同类型,对应着不同的存取方法规范: @@ -481,7 +481,7 @@ Objective-C的方法名通常都比较长,这是为了让程序有更好地可 - (void)getLineDash:(float *)pattern count:(int *)count phase:(float *)phase; ``` -###命名委托(Delegate) +### 命名委托(Delegate) 当特定的事件发生时,对象会触发它注册的委托方法。委托是Objective-C中常用的传递消息的方式。委托有它固定的命名范式。 @@ -504,7 +504,7 @@ Objective-C的方法名通常都比较长,这是为了让程序有更好地可 - (BOOL)windowShouldClose:(id)sender; ``` -###集合操作类方法(Collection Methods) +### 集合操作类方法(Collection Methods) 有些对象管理着一系列其它对象或者元素的集合,需要使用类似“增删查改”的方法来对集合进行操作,这些方法的命名范式一般为: @@ -539,7 +539,7 @@ Objective-C的方法名通常都比较长,这是为了让程序有更好地可 - (void)setParentWindow:(NSWindow *)window; ``` -###命名函数(Functions) +### 命名函数(Functions) 在很多场合仍然需要用到函数,比如说如果一个对象是一个单例,那么应该使用函数来代替类方法执行相关操作。 @@ -574,7 +574,7 @@ const char *NSGetSizeAndAlignment(const char *typePtr, unsigned int *sizep, unsi BOOL NSDecimalIsNotANumber(const NSDecimal *decimal) ``` -###命名属性和实例变量(Properties&Instance Variables) +### 命名属性和实例变量(Properties&Instance Variables) 属性和对象的存取方法相关联,属性的第一个字母小写,后续单词首字母大写,不必添加前缀。属性按功能命名成名词或者动词: @@ -605,7 +605,7 @@ BOOL NSDecimalIsNotANumber(const NSDecimal *decimal) *按苹果的说法,不建议在除了`init`和`dealloc`方法以外的地方直接访问实例变量,但很多人认为直接访问会让代码更加清晰可读,只在需要计算或者执行操作的时候才使用存取方法访问,我就是这种习惯,所以这里不作要求。* -###命名常量(Constants) +### 命名常量(Constants) 如果要定义一组相关的常量,尽量使用枚举类型(enumerations),枚举类型的命名规则和函数的命名规则相同。 建议使用 `NS_ENUM` 和 `NS_OPTIONS` 宏来定义枚举类型,参见官方的 [Adopting Modern Objective-C](https://developer.apple.com/library/ios/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObjective-C/AdoptingModernObjective-C.html) 一文: @@ -646,7 +646,7 @@ const float NSLightGray; 注意到一般由编译器定义的宏会在前后都有一个`__`,比如*`__MACH__`*。 -###命名通知(Notifications) +### 命名通知(Notifications) 通知常用于在模块间传递消息,所以通知要尽可能地表示出发生的事件,通知的命名范式是: @@ -661,11 +661,11 @@ NSTextViewDidChangeSelectionNotification NSColorPanelColorDidChangeNotification ``` -##注释 +## 注释 读没有注释代码的痛苦你我都体会过,好的注释不仅能让人轻松读懂你的程序,还能提升代码的逼格。注意注释是为了让别人看懂,而不是仅仅你自己。 -###文件注释 +### 文件注释 每一个文件都**必须**写文件注释,文件注释通常包含 @@ -714,7 +714,7 @@ NSColorPanelColorDidChangeNotification *文件注释的格式通常不作要求,能清晰易读就可以了,但在整个工程中风格要统一。* -###代码注释 +### 代码注释 好的代码应该是“自解释”(self-documenting)的,但仍然需要详细的注释来说明参数的意义、返回值、功能以及可能的副作用。 @@ -775,19 +775,19 @@ NSColorPanelColorDidChangeNotification **定义在头文件里的接口方法、属性必须要有注释!** -##编码风格 +## 编码风格 每个人都有自己的编码风格,这里总结了一些比较好的Cocoa编程风格和注意点。 -###不要使用new方法 +### 不要使用new方法 尽管很多时候能用`new`代替`alloc init`方法,但这可能会导致调试内存时出现不可预料的问题。Cocoa的规范就是使用`alloc init`方法,使用`new`会让一些读者困惑。 -###Public API要尽量简洁 +### Public API要尽量简洁 共有接口要设计的简洁,满足核心的功能需求就可以了。不要设计很少会被用到,但是参数极其复杂的API。如果要定义复杂的方法,使用类别或者类扩展。 -###\#import和\#include +### \#import和\#include `#import`是Cocoa中常用的引用头文件的方式,它能自动防止重复引用文件,什么时候使用`#import`,什么时候使用`#include`呢? @@ -805,7 +805,7 @@ NSColorPanelColorDidChangeNotification 为什么不全部使用`#import`呢?主要是为了保证代码在不同平台间共享时不出现问题。 -###引用框架的根头文件 +### 引用框架的根头文件 上面提到过,每一个框架都会有一个和框架同名的头文件,它包含了框架内接口的所有引用,在使用框架的时候,应该直接引用这个根头文件,而不是其它子模块的头文件,即使是你只用到了其中的一小部分,编译器会自动完成优化的。 @@ -818,7 +818,7 @@ NSColorPanelColorDidChangeNotification #import ``` -###BOOL的使用 +### BOOL的使用 BOOL在Objective-C中被定义为`signed char`类型,这意味着一个BOOL类型的变量不仅仅可以表示`YES`(1)和`NO`(0)两个值,所以永远**不要**将BOOL类型变量直接和`YES`比较: @@ -861,11 +861,11 @@ if (great) 另外BOOL类型可以和`_Bool`,`bool`相互转化,但是**不能**和`Boolean`转化。 -###使用ARC +### 使用ARC 除非想要兼容一些古董级的机器和操作系统,我们没有理由放弃使用ARC。在最新版的Xcode(6.2)中,ARC是自动打开的,所以直接使用就好了。 -###在init和dealloc中不要用存取方法访问实例变量 +### 在init和dealloc中不要用存取方法访问实例变量 当`init``dealloc`方法被执行时,类的运行时环境不是处于正常状态的,使用存取方法访问变量可能会导致不可预料的结果,因此应当在这两个方法内直接访问实例变量。 @@ -897,11 +897,11 @@ if (great) } ``` -###按照定义的顺序释放资源 +### 按照定义的顺序释放资源 在类或者Controller的生命周期结束时,往往需要做一些扫尾工作,比如释放资源,停止线程等,这些扫尾工作的释放顺序应当与它们的初始化或者定义的顺序保持一致。这样做是为了方便调试时寻找错误,也能防止遗漏。 -###保证NSString在赋值时被复制 +### 保证NSString在赋值时被复制 `NSString`非常常用,在它被传递或者赋值时应当保证是以复制(copy)的方式进行的,这样可以防止在不知情的情况下String的值被其它对象修改。 @@ -911,7 +911,7 @@ if (great) } ``` -###使用NSNumber的语法糖 +### 使用NSNumber的语法糖 使用带有`@`符号的语法糖来生成NSNumber对象能使代码更简洁: @@ -924,7 +924,7 @@ enum { NSNumber *myEnum = @(kMyEnum); ``` -###nil检查 +### nil检查 因为在Objective-C中向nil对象发送命令是不会抛出异常或者导致崩溃的,只是完全的“什么都不干”,所以,只在程序中使用nil来做逻辑上的检查。 @@ -942,11 +942,11 @@ if (nil == objc) { } ``` -###属性的线程安全 +### 属性的线程安全 定义一个属性时,编译器会自动生成线程安全的存取方法(Atomic),但这样会大大降低性能,特别是对于那些需要频繁存取的属性来说,是极大的浪费。所以如果定义的属性不需要线程保护,记得手动添加属性关键字`nonatomic`来取消编译器的优化。 -###点分语法的使用 +### 点分语法的使用 不要用点分语法来调用方法,只用来访问属性。这样是为了防止代码可读性问题。 @@ -961,7 +961,7 @@ NSUInteger numberOfItems = array.count; array.release; ``` -###Delegate要使用弱引用 +### Delegate要使用弱引用 一个类的Delegate对象通常还引用着类本身,这样很容易造成引用循环的问题,所以类的Delegate属性要设置为弱引用。 diff --git a/Pods/BAButton/README.md b/Pods/BAButton/README.md index b5c06ee..525b6ea 100755 --- a/Pods/BAButton/README.md +++ b/Pods/BAButton/README.md @@ -15,7 +15,7 @@ ## 2016.04.4 --- -###示例展示: +### 示例展示: ![image](https://raw.githubusercontent.com/boai/BAButton/master/BAButtonDemo/images/image1.png) ![image](https://raw.githubusercontent.com/boai/BAButton/master/BAButtonDemo/images/image2.png) @@ -23,7 +23,7 @@ >##完全实现button的自定义, -###pod 导入: pod 'BAButton', '~> 1.0.1' +### pod 导入: pod 'BAButton', '~> 1.0.1' 如果发现pod search BAButton 搜索出来的不是最新版本,需要在终端执行cd转换文件路径命令退回到desktop,然后执行pod setup命令更新本地spec缓存(可能需要几分钟),然后再搜索就可以了 具体步骤: - pod setup : 初始化 @@ -31,7 +31,7 @@ - pod search BAButton -###项目中导入头文件: +### 项目中导入头文件: ``` #import 即可 ``` diff --git a/Pods/BACustomAlertView/README.md b/Pods/BACustomAlertView/README.md index eed0405..5e44d1d 100644 --- a/Pods/BACustomAlertView/README.md +++ b/Pods/BACustomAlertView/README.md @@ -26,7 +26,7 @@ * 2、可以添加文字和图片,且可以滑动查看 * 1、理论完全兼容目前所有 iOS 系统版本 -####~~注:目前此版本只支持竖屏适配,小伙伴儿记得哦!~~ +#### ~~注:目前此版本只支持竖屏适配,小伙伴儿记得哦!~~ --- diff --git a/Pods/IQKeyboardManager/README.md b/Pods/IQKeyboardManager/README.md index 044fdb1..14846b3 100644 --- a/Pods/IQKeyboardManager/README.md +++ b/Pods/IQKeyboardManager/README.md @@ -15,7 +15,7 @@ Often while developing an app, We ran into an issues where the iPhone keyboard slide up and cover the `UITextField/UITextView`. `IQKeyboardManager` allows you to prevent issues of the keyboard sliding up and cover `UITextField/UITextView` without needing you to enter any code and no additional setup required. To use `IQKeyboardManager` you simply need to add source files to your project. -####Key Features +#### Key Features [![Issue Stats](http://issuestats.com/github/hackiftekhar/iqkeyboardmanager/badge/pr?style=flat)](http://issuestats.com/github/hackiftekhar/iqkeyboardmanager) [![Issue Stats](http://issuestats.com/github/hackiftekhar/iqkeyboardmanager/badge/issue?style=flat)](http://issuestats.com/github/hackiftekhar/iqkeyboardmanager) @@ -171,7 +171,7 @@ You can find some manual management tweaks & examples [here](https://github.com/ [![IQKeyboardManager CFD](https://raw.githubusercontent.com/hackiftekhar/IQKeyboardManager/v3.3.0/Screenshot/IQKeyboardManagerCFD.jpg)](https://raw.githubusercontent.com/hackiftekhar/IQKeyboardManager/v3.3.0/Screenshot/IQKeyboardManagerCFD.jpg) -##Properties and functions usage:- +## Properties and functions usage:- You can find some documentation about properties, methods and their uses [here](https://github.com/hackiftekhar/IQKeyboardManager/blob/master/PROPERTIES & FUNCTIONS.md). diff --git a/Pods/JMRoundedCorner/README.md b/Pods/JMRoundedCorner/README.md index cc14382..daaa3cb 100644 --- a/Pods/JMRoundedCorner/README.md +++ b/Pods/JMRoundedCorner/README.md @@ -1,168 +1,168 @@ # JMRoundedCorner - - -[![LICENSE](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/raozhizhen/JMRoundedCorner/master/LICENSE)  -[![CocoaPods](http://img.shields.io/cocoapods/v/JMRoundedCorner.svg?style=flat)](http://cocoapods.org/?q=JMRoundedCorner)  -[![SUPPORT](https://img.shields.io/badge/support-iOS%207%2B%20-blue.svg?style=flat)](https://en.wikipedia.org/wiki/IOS_7)  + + +[![LICENSE](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/raozhizhen/JMRoundedCorner/master/LICENSE)  +[![CocoaPods](http://img.shields.io/cocoapods/v/JMRoundedCorner.svg?style=flat)](http://cocoapods.org/?q=JMRoundedCorner)  +[![SUPPORT](https://img.shields.io/badge/support-iOS%207%2B%20-blue.svg?style=flat)](https://en.wikipedia.org/wiki/IOS_7)  [![BLOG](https://img.shields.io/badge/blog-raozhizhen.com-orange.svg?style=flat)](http://raozhizhen.com)  -###Swift 版本:[JMRoundedCornerSwift](https://github.com/raozhizhen/JMRoundedCornerSwift) - - -当我们需要给一个 View 设置圆角的时候,一般会这样写 - -```objc -_label.layer.cornerRadius = 10; -_label.layer.masksToBounds = YES; -``` - -cornerRadius 和 maskToBounds 独立作用的时候都不会有太大的性能问题,但是当他俩结合在一起,就触发了离屏渲染, -Instrument的 Core Animation 有一个叫做 Color Offscreen-Rendered Yellow 的选项。它会将已经被渲染到屏幕外缓冲区的区域标注为黄色,下图中黄色的部分就是离屏渲染的地方。 - -![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/IMG_2590.PNG?raw=true) - -####离屏渲染是什么? - -离屏渲染绘制 layer tree 中的一部分到一个新的缓存里面(这个缓存不是屏幕,是另一个地方),然后再把这个缓存渲染到屏幕上面。一般来说,你需要避免离屏渲染。因为这个开销很大。在屏幕上面直接合成层要比先创建一个离屏缓存然后在缓存上面绘制,最后再绘制缓存到屏幕上面快很多。这里面有 2 个上下文环境的切换(切换到屏幕外缓存环境,和屏幕环境)。 - -####解决方案 - -如果你的 view 不需要让子视图超出部分不显示,且不需要给 view 的 image 绘制圆角, - -可以查看 cornerRadius 属性的注释: - - By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners. - -这个属性会影响 layer 的背景颜色和 border,所以如下代码即可避免离屏渲染。 - -```objc -view.layer.cornerRadius = radius; -view.layer.backgroundColor = backgroundColor.CGColor; -``` - -但如果需要给 view 的 image 绘制圆角,如 UIImageView.image 和 UIButton 的背景图片。 - -则可以用 GraphicsContext 绘制一张带圆角的 image 给 view 来避免离屏渲染。 - -我将这个过程封装了一下 - -####使用 JMRoundedCorner 来绘制圆角 - - - platform :ios, '7.0' - - pod 'JMRoundedCorner' - - #import "UIView+RoundedCorner.h" - - - -#####给 view 设置一个圆角边框 - -```objc -- (void)jm_setCornerRadius:(CGFloat)radius withBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth; -``` - -#####给 view 设置一个圆角背景颜色 - -```objc -- (void)jm_setCornerRadius:(CGFloat)radius withBackgroundColor:(UIColor *)backgroundColor; -``` - -#####给 view 设置一个圆角背景图 - -```objc -- (void)jm_setCornerRadius:(CGFloat)radius withImage:(UIImage *)image; -``` - -#####给 view 设置一个 contentMode 模式的圆角背景图 - -```objc -- (void)jm_setCornerRadius:(CGFloat)radius withImage:(UIImage *)image contentMode:(UIViewContentMode)contentMode; -``` - -#####设置所有属性配置出一个圆角背景图 - -```objc -- (void)jm_setCornerRadius:(CGFloat)radius withBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth backgroundColor:(UIColor *)backgroundColor backgroundImage:(UIImage *)backgroundImage contentMode:(UIViewContentMode)contentMode; -``` - -#####代码示例 -```objc - _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 40, 40)]; - [_avatarView jm_setCornerRadius:20 withImage:[UIImage imageNamed:@"avatar.jpg"]]; - [self.contentView addSubview:_avatarView]; -``` - -```objc -//添加占位图 - _avatarView.image = [placeholderImage jm_imageWithRoundedCornersAndSize:CGSizeMake(60, 60) andCornerRadius:30]; - -//下载完之后设置圆角 image -[[SDWebImageManager sharedManager] downloadImageWithURL:_model.avatarURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { - if (image) { - [_avatarView jm_setCornerRadius:30 withImage:image]; - } -}]; -``` - -这样,绘制出了圆角,也可以避免在大量 view 离屏渲染的时候拖慢 FPS -![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/IMG_2580.PNG?raw=true) - - -将 Demo 下下来,试试使用 JMRoundedCorner 带来的顺滑提升。 - -##### 支持通过 JMRadius 设置4个角为不同的弧度,角度优先级为左上 > 右上 > 左下 > 右下,例如: - -```objc -[_label jm_setJMRadius:JMRadiusMake(0, 10, 0, 10) withBorderColor:[UIColor redColor] borderWidth:0.5]; -``` - -![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/JMRoundedCornerGIF.gif?raw=true) -####联系我 - -- QQ:337519524 -- 邮箱:raozhizhen@gmail.com - -####感谢 - -- [reviewcode.cn](http://www.reviewcode.cn/article.html?reviewId=7) - -- [Getting Pixels Onto the Screen](https://www.objc.io/issues/3-views/moving-pixels-onto-the-screen/) - -####性能上的优缺点 - -优点:没有了离屏渲染,调整了 image 的像素大小以避免不必要的缩放 - +### Swift 版本:[JMRoundedCornerSwift](https://github.com/raozhizhen/JMRoundedCornerSwift) + + +当我们需要给一个 View 设置圆角的时候,一般会这样写 + +```objc +_label.layer.cornerRadius = 10; +_label.layer.masksToBounds = YES; +``` + +cornerRadius 和 maskToBounds 独立作用的时候都不会有太大的性能问题,但是当他俩结合在一起,就触发了离屏渲染, +Instrument的 Core Animation 有一个叫做 Color Offscreen-Rendered Yellow 的选项。它会将已经被渲染到屏幕外缓冲区的区域标注为黄色,下图中黄色的部分就是离屏渲染的地方。 + +![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/IMG_2590.PNG?raw=true) + +#### 离屏渲染是什么? + +离屏渲染绘制 layer tree 中的一部分到一个新的缓存里面(这个缓存不是屏幕,是另一个地方),然后再把这个缓存渲染到屏幕上面。一般来说,你需要避免离屏渲染。因为这个开销很大。在屏幕上面直接合成层要比先创建一个离屏缓存然后在缓存上面绘制,最后再绘制缓存到屏幕上面快很多。这里面有 2 个上下文环境的切换(切换到屏幕外缓存环境,和屏幕环境)。 + +#### 解决方案 + +如果你的 view 不需要让子视图超出部分不显示,且不需要给 view 的 image 绘制圆角, + +可以查看 cornerRadius 属性的注释: + + By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners. + +这个属性会影响 layer 的背景颜色和 border,所以如下代码即可避免离屏渲染。 + +```objc +view.layer.cornerRadius = radius; +view.layer.backgroundColor = backgroundColor.CGColor; +``` + +但如果需要给 view 的 image 绘制圆角,如 UIImageView.image 和 UIButton 的背景图片。 + +则可以用 GraphicsContext 绘制一张带圆角的 image 给 view 来避免离屏渲染。 + +我将这个过程封装了一下 + +#### 使用 JMRoundedCorner 来绘制圆角 + + + platform :ios, '7.0' + + pod 'JMRoundedCorner' + + #import "UIView+RoundedCorner.h" + + + +##### 给 view 设置一个圆角边框 + +```objc +- (void)jm_setCornerRadius:(CGFloat)radius withBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth; +``` + +##### 给 view 设置一个圆角背景颜色 + +```objc +- (void)jm_setCornerRadius:(CGFloat)radius withBackgroundColor:(UIColor *)backgroundColor; +``` + +##### 给 view 设置一个圆角背景图 + +```objc +- (void)jm_setCornerRadius:(CGFloat)radius withImage:(UIImage *)image; +``` + +##### 给 view 设置一个 contentMode 模式的圆角背景图 + +```objc +- (void)jm_setCornerRadius:(CGFloat)radius withImage:(UIImage *)image contentMode:(UIViewContentMode)contentMode; +``` + +##### 设置所有属性配置出一个圆角背景图 + +```objc +- (void)jm_setCornerRadius:(CGFloat)radius withBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth backgroundColor:(UIColor *)backgroundColor backgroundImage:(UIImage *)backgroundImage contentMode:(UIViewContentMode)contentMode; +``` + +##### 代码示例 +```objc + _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 40, 40)]; + [_avatarView jm_setCornerRadius:20 withImage:[UIImage imageNamed:@"avatar.jpg"]]; + [self.contentView addSubview:_avatarView]; +``` + +```objc +//添加占位图 + _avatarView.image = [placeholderImage jm_imageWithRoundedCornersAndSize:CGSizeMake(60, 60) andCornerRadius:30]; + +//下载完之后设置圆角 image +[[SDWebImageManager sharedManager] downloadImageWithURL:_model.avatarURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (image) { + [_avatarView jm_setCornerRadius:30 withImage:image]; + } +}]; +``` + +这样,绘制出了圆角,也可以避免在大量 view 离屏渲染的时候拖慢 FPS +![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/IMG_2580.PNG?raw=true) + + +将 Demo 下下来,试试使用 JMRoundedCorner 带来的顺滑提升。 + +##### 支持通过 JMRadius 设置4个角为不同的弧度,角度优先级为左上 > 右上 > 左下 > 右下,例如: + +```objc +[_label jm_setJMRadius:JMRadiusMake(0, 10, 0, 10) withBorderColor:[UIColor redColor] borderWidth:0.5]; +``` + +![](https://github.com/raozhizhen/JMRoundedCorner/blob/master/JMRoundedCornerGIF.gif?raw=true) +#### 联系我 + +- QQ:337519524 +- 邮箱:raozhizhen@gmail.com + +#### 感谢 + +- [reviewcode.cn](http://www.reviewcode.cn/article.html?reviewId=7) + +- [Getting Pixels Onto the Screen](https://www.objc.io/issues/3-views/moving-pixels-onto-the-screen/) + +#### 性能上的优缺点 + +优点:没有了离屏渲染,调整了 image 的像素大小以避免不必要的缩放 + 缺点:会造成图层混合,且因为只是绘制了一个带圆角的图片,所以不能使子视图超出圆角部分不显示。 -注意:内存会持续提升,是正常现象,点击 home 键内存会回到正常水平,并非内存泄漏,只是绘制的缓存,在内存不足时会自动释放。 - -####更新日志 +注意:内存会持续提升,是正常现象,点击 home 键内存会回到正常水平,并非内存泄漏,只是绘制的缓存,在内存不足时会自动释放。 + +#### 更新日志 - 2016/4/25 1.2.0版本 : 使用 NSOperationQueue 代替 dispatch_queue,当重复设置圆角的时候会自动 cancel 上一次操作,感谢 **[kudocc](https://github.com/kudocc)** 的 pull request。 - -- 2016/4/18 1.1.2版本 : 修改一点小 BUG - -- 2016/3/14 1.1.1版本 : 解决设置 contentMode 效果的一些 BUG。 - -- 2016/3/12 1.1.0版本 : 接口带上了 jm_ 前缀,JMRadius 添加圆角优先级,经过大量测试,解决细节上的一些小BUG。 - -- 2016/3/6 1.0.5版本 : 优化 - -- 2016/3/4 1.0.4版本 : 修复有背景图片就不绘制背景颜色的 BUG - -- 2016/3/3 1.0.3版本 : 修复 label 里如果没有汉字,文字就不显示的 BUG,以及做了使 view 落在像素点上的优化。 - -- 2016/3/1 1.0.2版本 :修复 backgroundColor 参数无效的 BUG - -- 2016/3/1 1.0.1版本 :优化 - -- 2016/2/28 1.0.0版本 :发布正式版本 - -- 2016/2/26 0.0.4版本 :去掉了 size 参数及支持 JMRadius 设置4个角为不同的弧度 - -- 2016/2/25 0.0.3版本 :去掉了 UIImageView 这个中间控件 - -- 2016/2/24 0.0.2版本 :支持设置背景图片的绘制模式(cotentmode) - -- 2016/2/23 0.0.1版本 :绘制一个圆角 image + +- 2016/4/18 1.1.2版本 : 修改一点小 BUG + +- 2016/3/14 1.1.1版本 : 解决设置 contentMode 效果的一些 BUG。 + +- 2016/3/12 1.1.0版本 : 接口带上了 jm_ 前缀,JMRadius 添加圆角优先级,经过大量测试,解决细节上的一些小BUG。 + +- 2016/3/6 1.0.5版本 : 优化 + +- 2016/3/4 1.0.4版本 : 修复有背景图片就不绘制背景颜色的 BUG + +- 2016/3/3 1.0.3版本 : 修复 label 里如果没有汉字,文字就不显示的 BUG,以及做了使 view 落在像素点上的优化。 + +- 2016/3/1 1.0.2版本 :修复 backgroundColor 参数无效的 BUG + +- 2016/3/1 1.0.1版本 :优化 + +- 2016/2/28 1.0.0版本 :发布正式版本 + +- 2016/2/26 0.0.4版本 :去掉了 size 参数及支持 JMRadius 设置4个角为不同的弧度 + +- 2016/2/25 0.0.3版本 :去掉了 UIImageView 这个中间控件 + +- 2016/2/24 0.0.2版本 :支持设置背景图片的绘制模式(cotentmode) + +- 2016/2/23 0.0.1版本 :绘制一个圆角 image diff --git a/Pods/Masonry/README.md b/Pods/Masonry/README.md index 2b59a48..f2a1b17 100644 --- a/Pods/Masonry/README.md +++ b/Pods/Masonry/README.md @@ -1,4 +1,4 @@ -#Masonry [![Build Status](https://travis-ci.org/SnapKit/Masonry.svg?branch=master)](https://travis-ci.org/SnapKit/Masonry) [![Coverage Status](https://img.shields.io/coveralls/SnapKit/Masonry.svg?style=flat-square)](https://coveralls.io/r/SnapKit/Masonry) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pod Version](https://img.shields.io/cocoapods/v/Masonry.svg?style=flat) +# Masonry [![Build Status](https://travis-ci.org/SnapKit/Masonry.svg?branch=master)](https://travis-ci.org/SnapKit/Masonry) [![Coverage Status](https://img.shields.io/coveralls/SnapKit/Masonry.svg?style=flat-square)](https://coveralls.io/r/SnapKit/Masonry) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pod Version](https://img.shields.io/cocoapods/v/Masonry.svg?style=flat) **Masonry is still actively maintained, we are committed to fixing bugs and merging good quality PRs from the wider community. However if you're using Swift in your project, we recommend using [SnapKit](https://github.com/SnapKit/SnapKit) as it provides better type safety with a simpler API.** diff --git a/Pods/MyLayout/README.md b/Pods/MyLayout/README.md index 775c47b..7a15e68 100644 --- a/Pods/MyLayout/README.md +++ b/Pods/MyLayout/README.md @@ -6,7 +6,7 @@ [![QQ](https://img.shields.io/badge/QQ-156355113-yellow.svg?style=flat)]() [![GitHub stars](https://img.shields.io/github/stars/youngsoft/MyLinearLayout.svg)](https://github.com/youngsoft/MyLinearLayout/stargazers) -##MyLayout(2016.12.5) +## MyLayout(2016.12.5) MyLayout is a simple and easy objective-c framework for iOS view layout. MyLayout provides some simple functions to build a variety of complex interface. It integrates the functions including: Autolayout and SizeClass of iOS, five layout classes of Android, float and flex-box and bootstrap of HTML/CSS. The MyLayout's Swift version are named: **[TangramKit](https://github.com/youngsoft/TangramKit)** @@ -58,15 +58,15 @@ MyLayout is a simple and easy objective-c framework for iOS view layout. MyLayou ``` -##Architecture +## Architecture ![demo](https://raw.githubusercontent.com/youngsoft/MyLinearLayout/master/MyLayout/MyLayoutClass.png) -###MyLayoutPos +### MyLayoutPos `MyLayoutPos` is represent to the position of a view. UIView provides six extension variables:leftPos, topPos, bottomPos, rightPos, centerXPos, centerYPos to set view's margin or space distance between self and others. You can use `equalTo` method to set NSNumber or MyLayoutPos or NSArray value. there are six simple variables:myLeftMargin,myTopMargin,myBottomMargin,myRightMargin,myCenterXOffset,myCenterYOffset use to set NSNumber value. eg. `A.leftPos.equalTo(@10); <==> A.myLeftMargin = 10;` -###MyLayoutSize +### MyLayoutSize `MyLayoutSize` is represent to the size of a view. UIView provides two extension variables:widthDime,heightDime to set view's width and height dimension. You can use `equalTo` method to set NSNumber or MyLayoutSize or NSArray value. there are two simple variables: myWidth, myHeight use to set NSNumber value. eg. `A.widthDime.equalTo(@10); <==> A.myWidth = 10;` @@ -487,7 +487,7 @@ to set Size Classes Characteristics like below: ![演示效果图](https://raw.githubusercontent.com/youngsoft/MyLinearLayout/master/MyLayout/layoutdemo7.gif) -##How To Get Started +## How To Get Started [Download MyLayout](https://github.com/youngsoft/MyLinearLayout/archive/master.zip) and try out the included iPad and iPhone example apps Read FAQ, or articles below: @@ -503,7 +503,7 @@ Read FAQ, or articles below: Because my english is poor so I just only can support chinese articles,and I wish somebody can help me translate to english. -##Communication +## Communication - If you need help, use Stack Overflow or Baidu. (Tag 'mylayout') @@ -542,7 +542,7 @@ Then, run the following command: -##FAQ +## FAQ * If you use MyLayout runtime cause 100% CPU usage said appeared constraint conflict, please check the subview's constraint set. * If you use MyLayout exception crashed in MyBaseLayout *willMoveToSuperview* method. it does not matter, just remove the exception break setting in CMD+7. diff --git a/Pods/SDAutoLayout/README.md b/Pods/SDAutoLayout/README.md index d5100f3..d362751 100644 --- a/Pods/SDAutoLayout/README.md +++ b/Pods/SDAutoLayout/README.md @@ -1,6 +1,6 @@ # SDAutoLayout(一行代码搞定自动布局!) -##众多公司和个人开发者已经使用本库布局: +## 众多公司和个人开发者已经使用本库布局: SDAutoLayout使用者开发的部分app截图 http://www.jianshu.com/p/9bc04d3effb8 一行代码搞定自动布局!致力于做最简单易用的Autolayout库。The most easy way for autolayout. @@ -9,7 +9,7 @@ SDAutoLayout使用者开发的部分app截图 http://www.jianshu.com/p/9bc04d3ef 497140713(1群) 519489682(2群已满) -##Pod支持: +## Pod支持: 支持pod: pod 'SDAutoLayout', '~> 2.1.3' @@ -73,7 +73,7 @@ SDAutoLayout使用者开发的部分app截图 http://www.jianshu.com/p/9bc04d3ef ## tableview和cell高度自适应: -####普通(简化)版【推荐使用】:tableview 高度自适应设置只需要2步 +#### 普通(简化)版【推荐使用】:tableview 高度自适应设置只需要2步 1. >> 设置cell高度自适应: // cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view) @@ -89,7 +89,7 @@ SDAutoLayout使用者开发的部分app截图 http://www.jianshu.com/p/9bc04d3ef } -####升级版(适应于cell条数少于100的tableview):tableview 高度自适应设置只需要2步 +#### 升级版(适应于cell条数少于100的tableview):tableview 高度自适应设置只需要2步 1. >> 设置cell高度自适应: // cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view) diff --git a/README.md b/README.md index edf6fba..62af315 100755 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ iOS 10技术开发群 | `479663605` | --- ## 4、项目简介 和 使用指南 -####4.1、项目简介
+#### 4.1、项目简介
**主要使用 MVVM 和 MVC 设计模式,共分为三大类:**
**4.1.1、Main**