我有一个现有的 iPad 应用程序(XCode 4.6、ARC、Storyboards 和 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];
}
我的问题是:使用CG绘图方法时我必须做一些不同的事情吗?左侧网格、顶部网格和中心网格都以相同的方式绘制。背景颜色在绘图下方的 UIView 上。顶部网格的唯一约束是宽度和高度。