【周报】2020.03.02-2020.03.08

276 阅读1分钟

class

  1. UUID

术语UUID代表通用唯一标识符。在Swift中,我们可以使用该UUID结构生成UUID 。

let identifier = UUID()
print(identifier)
// Output: 8D31B96A-02AC-4531-976F-A455686F8FE2
  1. CAShapeLayer
  • CAShapeLAyer 可以被觸碰和填充,並且他們的線條屬性可以被進行調節。

  • CAShapeLAyer 還具有許多動畫的特性,這使開發人員人員可以創建吸引人的動畫效果。

  • 最重要的是 CAShapeLayer 在完全的在 GPU 上渲染,使其非常快速。

  1. UIBezierPath
  • 在iPad出现之前,大部分定义绘图只能够使用Core Graphics,因为UIKit并不能绘制任意形状。
  • 在iOS3.2中添加了UIBezierPath更高级的API来绘制。实际上UIBezierPath是对CGPathRef的封装。
  • UIKit依然缺乏对渐变、阴影等高级特性的支持。但UIKit却可以非常方便的实现大部分常见的自定义绘制。
  1. DispatchWorkItem

The DispatchWorkItem class is an encapsulation of the concept of work item.

A dispatch work item has a cancel flag. If it is cancelled before running, the dispatch queue won’t execute it and will skip it. If it is cancelled during its execution, the cancel property return True. In that case, we can abort the execution

  1. UIViewControllerAnimatedTransitioning

要自定义 navigation push/pop animation 的时候可以创建一个遵守该协议的类,实现两个协议方法即可自定义转场动画

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval

func animateTransition(using transitionContext: UIViewControllerContextTransitioning)

tips

给 navigation push 添加 completion block

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    // handle completion here
}];

[self.navigationController popViewControllerAnimated:YES];

[CATransaction commit];

links

iOS App 如何產生獨一無二的 ID

How To Generate A Random Unique Identifier With UUID In Swift

利用 CAShapeLayer 和 mask 將 View 變成任意形狀

Swift — 畫個圖案吧( CAShapeLayer )

UIBezierPath

Operation VS DispatchWorkItem

Swift sweet bits: the Dispatch framework (iOS 10 +)