Có hai phương pháp drawRect:CGContextSaveGState vs UIGraphicsPushContext
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// do drawing here
CGContextRestoreGState(context);
}
Và
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
// do drawing here
UIGraphicsPopContext();
}
UIGraphicsPushContext/UIGraphicsPopContext là từ UIKit khi CGContextSaveGState/CGContextRestoreGState là từ CoreGraphics.
Câu hỏi: Sự khác biệt giữa các phương pháp đó là gì? Cái nào tốt hơn để sử dụng? Có một số ví dụ chứng minh một phương pháp tốt hơn so với các phương pháp khác và ngược lại không?