let arr = Array<Int>()
let arr1 = [Int]()
let arr2: [Int] = []
let arr3 = [1,2,3]
let arr4 = Array<Int>(repeating: 1, count: 3)
写了这么久的 iOS,基本都是和界面布局打交道,平常在编码的过程中也逐渐积累了一些关于布局的心得,这里做个总结,既是对前面工作的总结,也希望能够给读这篇文章的人一些收获。
从 iOS 7 开始到 iOS 10,由于有了高斯模糊的 bar,ViewController 默认开启全屏布局,UIViewController 增加了两个属性:
open var edgesForExtendedLayout: UIRectEdge // Defaults to UIRectEdgeAll
open var extendedLayoutIncludesOpaqueBars: Bool // Defaults to NO, but bars are translucent by default on 7_0.
通过上图我们可以看到,每隔 1ms,instruments 会记录一次 call stack,然后把每个方法的调用次数累加,最后就得到需要分析的数据了。所以,time profiler 记录的并不是方法调用的 duration,而是方法在单位时间内调用的 times。
在 iOS 中,我们通过 Core Graphics (也叫 Quarz 2D) 来绘图,而在 Core Grapihcs 之上的 UIKit 又封装了如 UIBeizerPath 等高级 api,这里就来简单的谈谈基础和技巧。
对于 UIView 来说,我们可以重写 draw(_:)
方法来进行绘图,官方文档中对它的描述是:
Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that context so that its origin matches the origin of your view’s bounds rectangle.