-(void)viewMethod{ //1: 要明白uiview内部是这样实现 CALayer *layer1= [CALayer layer]; layer.delegate=self; [layer1 setNeedsDisplay]; [self.layer addSublayer:layer];}- (void)drawRect:(CGRect)rect{ //contex和ctx是相同的,所以在view画的东西都在上下文中。 CGContextRef context= UIGraphicsGetCurrentContext(); // Drawing code}-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{ [self drawRect:layer.frame]; //然后拿到 drawRect画的东西,放在图层上。}