2010-07-05 3 views
0

Je travaille avec CGContext pour créer un carré simple avec quatre points donnés (les points devraient faire un carré parfait). Cependant, au lieu d'un carré 200px x 200px, l'application iPad fait, à quoi ressemble, 680w par 300h. Est-ce que je manque quelque chose?Les largeurs de CGContext semblent être trop étirées

int beginPointX, beginPointY, gridSize, gridPadding; 

gridSize = 200; 
gridPadding = 10; 

beginPointX = gridPadding; // padding from left border 
beginPointY = gridPadding; // padding from top border 


// initiate UIGraphics method 
UIGraphicsBeginImageContext(self.view.frame.size); 

// set context for our UIGraphics method 
CGContextRef context = UIGraphicsGetCurrentContext(); 

// set some defaults for our CGContext 
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0); 
CGContextSetLineWidth(context, 1.0); 
CGContextBeginPath(context); 


// start 

// build outer box 
CGRect testRect = CGRectMake(beginPointX, beginPointY, (beginPointX + gridSize), (beginPointY + gridSize)); 
CGContextAddRect(context, testRect); 
CGContextStrokePath(context); 

/* 
NSLog(@"Line from %dx%d to %dx%d", beginPointX, beginPointY, beginPointX, (beginPointY + gridSize)); 
CGContextMoveToPoint(context, beginPointX, beginPointY); 
CGContextAddLineToPoint(context, beginPointX, (beginPointY + gridSize)); 
CGContextStrokePath(context); 

NSLog(@"Line from %dx%d to %dx%d", beginPointX, (beginPointY + gridSize), (beginPointX + gridSize), (beginPointY + gridSize)); 
CGContextMoveToPoint(context, beginPointX, (beginPointY + gridSize)); 
CGContextAddLineToPoint(context, (beginPointX + gridSize), (beginPointY + gridSize)); 
CGContextStrokePath(context); 

NSLog(@"Line from %dx%d to %dx%d", (beginPointX + gridSize), (beginPointY + gridSize), (beginPointX + gridSize), beginPointY); 
CGContextMoveToPoint(context, (beginPointX + gridSize), (beginPointY + gridSize)); 
CGContextAddLineToPoint(context, (beginPointX + gridSize), beginPointY); 
CGContextStrokePath(context); 

NSLog(@"Line from %dx%d to %dx%d", (beginPointX + gridSize), beginPointY, beginPointX, beginPointY); 
CGContextMoveToPoint(context, (beginPointX + gridSize), beginPointY); 
CGContextAddLineToPoint(context, beginPointX, beginPointY); 
CGContextStrokePath(context); 
*/ 

// insert set of instructions into our grid pointer 
grid.image = UIGraphicsGetImageFromCurrentImageContext(); 

Une chose à noter est que je travaille sur une application iPad qui a son orientation verrouillée dans le paysage (si cela fait une différence).

Répondre

1
CGRect CGRectMake (
    CGFloat x, 
    CGFloat y, 
    CGFloat width, 
    CGFloat height 
); 

Ainsi, cette ligne

CGRect testRect = CGRectMake(beginPointX, beginPointY, (beginPointX + gridSize), (beginPointY + gridSize)); 

devrait être

CGRect testRect = CGRectMake(beginPointX, beginPointY, gridSize, gridSize); 
+0

C'est ce que je reçois pour le travail à 02h30. Merci! –

Questions connexes