“drawViewHierarchyInRect”和“drawInContext”之间有什么区别?

时间:2015-03-30 07:46:40

标签: ios swift uiview

获得UIView的快照有两种选择:

选项1:

UIGraphicsBeginImageContextWithOptions(sampleView.bounds.size, false, UIScreen.mainScreen().scale)
sampleView.drawViewHierarchyInRect(sampleView.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

选项2:

UIGraphicsBeginImageContextWithOptions(sampleView.bounds.size, false, UIScreen.mainScreen().scale)
sampleView.layer.drawInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

有什么区别?

1 个答案:

答案 0 :(得分:0)

目前,我发现option1必须使用主队列,这是一个串行队列。但是,option2可以在后台队列

的后台完成它的工作