1.我在自定义函数里使用UIGraphicsGetCurrentContext()返回值是nil
2.上面的问题解决后,我给UIView添加了一个subLayer,而后我开始在drawRect中开始画图函数
针对上面的两个问题
1.是由于UIGraphicsGetCurrentContext()最好要写在drawRect()中,由于在drawRect()执行以前程序会将上下文压入栈中,因此在别的函数中调用可能会获得nil
2.缘由是由于定义的subLayer没有在context,使用subLayer.renderInContext(context!)将subLayer添加进去context程序