我有View
一些subviews
像Labels
和ImageViews
。subviews
可以有任何变换。我必须使用. View
_ PDF已创建,但当我将它们旋转到. 我不知道我在哪里做错了。我正在使用类别来绘制层次结构。CGContext
label
View
UIGraphicsBeginPDFContextToFile(myPathDocs, CGRectMake(0, 0, 612, 792), nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),bgColor.CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(),CGRectMake(0, 0, 612, 792));
[_pdfView drawHierarchy];
UIGraphicsEndPDFContext();
// Category
#import "UIView+HierarchicalDrawing.h"
@implementation UIView (HierarchicalDrawing)
- (void)drawHierarchy {
[self layoutSubviews];
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSaveGState(c);
CGContextTranslateCTM(c, self.frame.origin.x, self.frame.origin.y);
if (self.backgroundColor != nil) {
CGContextSetFillColorWithColor(c, [self.backgroundColor CGColor]);
CGContextFillRect(c, self.bounds);
}
if ([self isKindOfClass:[UIImageView class]]) {
if(self.layer.shadowColor) {
CGContextSetShadowWithColor(c, self.layer.shadowOffset, 0.0, self.layer.shadowColor);
}
}
if ([self isKindOfClass:[UILabel class]]) {
CGPoint centrePoint = self.center;
CGFloat angle = atan2f(self.transform.b, self.transform.a);
CGContextRotateCTM(c, angle);
}
[self drawRect:self.bounds];
if(self.clipsToBounds) CGContextClipToRect(c, self.bounds);
for(UIView *v in self.subviews) {
if(v.hidden) continue;
[v drawHierarchy];
}
// NSLog(@"counter is %d",counter);
CGContextRestoreGState(c);
}
@end