我有一個應用程序,我畫垂直線代表約會。他們沒有被繪製在我想要繪製的地方。這裏是目前正在制定什麼樣的例子:爲什麼不按照我通過的x,y設置繪製線條?
這是的代碼的適當部分用於配置x和y的每一個豎條,並繪製它:
// get shop hours from Preferences
NSDate *timeShopOpens; // GMT - 8
NSString *completeDateString;
PreferenceData *prefDataFound = [PreferenceData MR_findFirst];
if(prefDataFound) {
completeDateString = [NSString stringWithFormat:@"%@ %@",
[startDateParts objectAtIndex: 0],prefDataFound.aShopOpens]; // 2014-01-27 1000
timeShopOpens = [formatter dateFromString:completeDateString]; // NSDate 2014-01-27 18:00:00 +0000
}
// compute where to start drawing
NSDateComponents *components = [[NSCalendar currentCalendar]
components:NSCalendarUnitMinute
fromDate:timeShopOpens toDate:ai.aStartTime options:0];
float openAndStartMinutesDiff = [components minute]; // difference between shopOpen time and appt startTime in minutes
float fWhereToStartSegments = (openAndStartMinutesDiff/15); // gives the number of 15-minute segments to begin drawing
float startPosY = 28.0f + (fWhereToStartSegments * 12.5); // compute starting point (adjusted for line width)
// compute duration segments
components = [[NSCalendar currentCalendar]
components:NSCalendarUnitMinute
fromDate:ai.aStartTime toDate:ai.aEndTime options:0];
float startEndDiffMinutes = [components minute]; // difference between stop and start time in minutes <--OK
float fDurationSegments = (startEndDiffMinutes/15); // gives the number of 15-minute segments for duration
NSLog(@"\n\nstartPosY: %f\nopenAndStartMinutesDiff: %f\nfDurationSegments: %f",startPosY, openAndStartMinutesDiff, fDurationSegments);
// Start the line at this point (x,y)
float y = startPosY;
CGContextMoveToPoint(currentContext, column, y);
// compute end point (additional fDurationSegments takes line width into consideration)
CGContextAddLineToPoint(currentContext, column, startPosY + (fDurationSegments * 12.5) + fDurationSegments);
// draw the colored line
CGContextSetLineDash(currentContext, 0, nil, 0); // reset dashed line to straight line
CGContextSetLineWidth(currentContext, LINE_WIDTH); // Set the width for the lines
CGContextStrokePath(currentContext); // draw 'em
的相關對象的值在此處列出並且具有正確的值:
timeShopOpens: 2014-01-27 18:00:00 +0000
ai.aStartTimeOpens: 2014-01-27 18:15:00 +0000
startPosY: 40.500000
openAndStartMinutesDiff: 15.000000
fDurationSegments: 4.000000
fWhereToStartSegments: 1.000000
問題是:爲什麼繪圖不正確?
我希望得到這樣的事情手動創建再現:
你可以添加一張圖片,它顯示它應該是什麼樣子?如果我們有可視化參考,則更容易在代碼中找到錯誤。 – Hannes
大聲笑...不能添加它應該看起來像的圖片因爲我無法讓它工作!但是,如果您想象左上角的紅色條,則應該從1015水平線開始,然後下降至1115線。 – SpokaneDude
你可以使用photoshop或其他任何只是給一個粗略的草圖,會使它更容易 – Hannes