1

如何将变量设置为 a CGMakePoint

我尝试通过以下方式设置和调用变量:

我希望这个能工作。

float p0[] = {0, 100};

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:CGPointMake(p0)]; // this tells me I need two arguments

没有!

float *p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];

失败的!

NSObject *p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];

又一个错误!

id p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];

课程标准杆!

NSString *p0 = @"CGPointMake(0, 100)";

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];

我猜我只是将其转换为错误的类型。我不一定需要设置我的变量= CGPointMake(0, 100),但我确实需要能够将我的变量设置为我的坐标= (0, 100)

4

2 回答 2

9
CGPoint myPoint = CGPointMake(10.0, 50.0);

但是,请帮自己一个忙,正确地了解自己在做什么。你面临的问题是非常基础的,如果你停留在这个层面,很快就会出现无法解决的问题。

我通常会为初学者推荐 Big Nerd Ranch Guide 书籍,但我不能 100% 确定它们是否从对你来说足够基本的水平开始。

这并不是一种侮辱。只是作为一个友好的提示。

于 2013-05-26T17:25:22.100 回答
-1

我是对的......我将我的变量设置为错误的类型。一旦我将它设置为CGPoint它按预期工作。

CGPoint p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];
于 2013-05-26T17:24:19.063 回答