尝试这个 ,
-----------------------------示例代码-------------------- --------------
CGPoint pt =CGPointMake(20, 30);
NSValue *point = [NSValue valueWithCGPoint:pt];
CGPoint pt2 =CGPointMake(40, 40);
NSValue *point2 = [NSValue valueWithCGPoint:pt2];
NSMutableArray *allPoints =[[NSMutableArray alloc]initWithObjects:point,point2, nil];
NSLog(@"%@",allPoints);
// -------------output----------
// "NSPoint: {20, 30}",
// "NSPoint: {40, 40}"
int x=10; int y=20;
for (int i = 0; i < [allPoints count]; i++)
{
CGPoint pt = [[allPoints objectAtIndex:i] CGPointValue];
CGPoint newPt = CGPointMake(pt.x + x, pt.y + y);
NSValue *newEntry = [NSValue valueWithCGPoint:newPt];
[allPoints replaceObjectAtIndex:i withObject:newEntry];
}
NSLog(@"%@",allPoints);
// -------------output----------
// "NSPoint: {30, 50}",
// "NSPoint: {50, 60}"