1.我在自定義函數裏使用UIGraphicsGetCurrentContext()返回值是nil
2.上面的問題解決後,我給UIView添加了一個subLayer,而後我開始在drawRect中開始畫圖函數
針對上面的兩個問題
1.是由於UIGraphicsGetCurrentContext()最好要寫在drawRect()中,由於在drawRect()執行以前程序會將上下文壓入棧中,因此在別的函數中調用可能會獲得nil
2.緣由是由於定義的subLayer沒有在context,使用subLayer.renderInContext(context!)將subLayer添加進去context程序