将NSValue转换回CGPoint

时间:2014-07-30 21:27:45

标签: objective-c cocoa-touch cocoa cgpoint nsvalue

我像NSMutableArray那样存储了一堆CGPoint s

    safeZonePoints = [NSMutableArray array];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(234, 160)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(284, 210)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(334, 160)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(284, 10)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(234, 160)]];

现在我可以从数组中获取NSValue,但如何将NSValue转换回CGPoint

1 个答案:

答案 0 :(得分:3)

做这样的事情:

NSValue *cgpointObj = [NSValue valueWithCGPoint:CGPointMake(234, 160)];
CGPoint loc = cgpointObj.pointValue;

请查看以下链接:CGPoint to NSValue and reverse

回答你的问题应该足够了。