Ios6 使用CGContext绘图方法的自动布局?

Ios6 使用CGContext绘图方法的自动布局?,ios6,autolayout,xcode4.6,cg,Ios6,Autolayout,Xcode4.6,Cg,我有一个现有的iPad应用程序(XCode 4.6、ARC、故事板和iOS 6.2)。该应用程序在纵向模式下运行良好,但在横向模式下使用自动布局时效果不佳(见下图) 上图显示的是纵向模式,这是正确的 这是景观模式。。。请注意,它缺少名称和背景色 这是创建顶部网格的代码: -(void) drawTopGrid { // set up notification for redrawing topGrid [[NSNotificationCenter defaultCenter] addO

我有一个现有的iPad应用程序(XCode 4.6、ARC、故事板和iOS 6.2)。该应用程序在纵向模式下运行良好,但在横向模式下使用自动布局时效果不佳(见下图)

上图显示的是纵向模式,这是正确的

这是景观模式。。。请注意,它缺少名称和背景色

这是创建顶部网格的代码:

-(void) drawTopGrid  {

//  set up notification for redrawing topGrid
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(notificationToRedrawTopGrid:)
                                             name:@"redrawTopGrid" object:nil ];

//  setup for drawing grid
CGContextRef context = UIGraphicsGetCurrentContext();

#define START_VERTICAL_LINE  1  //  was 110
#define VERTICAL_LINE_INCREMENT 110  //  was 110
#define VERTICAL_LINE_LENGTH 52  // (compute based on number of hours)  

//  draw first vertical line
CGContextMoveToPoint(context, START_VERTICAL_LINE, 0); //start
CGContextAddLineToPoint(context, START_VERTICAL_LINE, VERTICAL_LINE_LENGTH); //draw to this point
CGContextStrokePath(context);  // draw it...

//  draw remainder of vertical lines (based on count of staff positions defined)  <--------------- TODO
for(int i = 2; i < 24; i += 2)  {  // will hold 6 staff positiions
    CGContextMoveToPoint(context, (i * VERTICAL_LINE_INCREMENT) - i, 0); //start
    CGContextAddLineToPoint(context, (i * VERTICAL_LINE_INCREMENT- i), VERTICAL_LINE_LENGTH); //draw to this point
    CGContextStrokePath(context);  // draw it...
}

//  get the staff names
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pathForStaffNames = [documentsDirectory stringByAppendingPathComponent:@"staffNames.plist"];
NSDictionary *staffDict = [NSDictionary dictionaryWithContentsOfFile:pathForStaffNames];
staffPos1 = [staffDict objectForKey:Slot1];
staffPos2 = [staffDict objectForKey:Slot2];
staffPos3 = [staffDict objectForKey:Slot3];
staffPos4 = [staffDict objectForKey:Slot4];
staffPos5 = [staffDict objectForKey:Slot5];
staffPos6 = [staffDict objectForKey:Slot6];

const float hourFontSize = 18;
UIFont *hourfont=[UIFont systemFontOfSize:hourFontSize];

//  draw staff names
[[UIColor redColor] set];
[staffPos1 drawAtPoint:CGPointMake(85, 12) withFont:hourfont];  //  increment is 220

[[UIColor blueColor] set];
[staffPos2 drawAtPoint:CGPointMake(303, 12) withFont:hourfont];

[[UIColor magentaColor] set];
[staffPos3 drawAtPoint:CGPointMake(523, 12) withFont:hourfont];

[[UIColor redColor] set];
[staffPos4 drawAtPoint:CGPointMake(743, 12) withFont:hourfont];

[[UIColor blueColor] set];
[staffPos5 drawAtPoint:CGPointMake(963, 12) withFont:hourfont];

[[UIColor magentaColor] set];
[staffPos6 drawAtPoint:CGPointMake(1183, 12) withFont:hourfont];
-(无效)drawTopGrid{
//设置重绘topGrid的通知
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@selector(notificationToRedrawTopGrid:)
名称:@“redrawTopGrid”对象:nil];
//绘制网格的设置
CGContextRef context=UIGraphicsGetCurrentContext();
#定义起始垂直线1//was 110
#定义垂直线增量110//was 110
#定义垂直线长度52/(根据小时数计算)
//画第一条垂直线
CGContextMoveToPoint(上下文,开始垂直线,0);//开始
CGContextAddLineToPoint(上下文,起始垂直线,垂直线长度);//绘制到此点
CGContextStrokePath(上下文);//绘制它。。。

//画出垂直线的剩余部分(基于定义的员工职位数量)以下是我一直在寻找的答案:

Core Graphics drawing对视图系统(包括自动布局)一无所知。如果您正在绘制的内容没有出现,很可能是因为您的视图几何图形导致传入的上下文没有生成图形所需的几何图形(通常的解决方案是让您的图形代码查看视图的边界,并在此基础上定位内容)