5

I am getting a point in NSPoint as:

NSPoint: {273,534}

I want to pass 273 and 534 into CGrectMake.
For example:

viewTwo.frame=CGRectMake(273,534,someValue,someValue)

I am not able to get the values in that NSpoint.
I tried passing it to NsArray and NSDictionary. Nothing works. Pls help

I use Po command in console and found the value which i need is in NSPoint. But dont know how to convert it

4

4 回答 4

5

NSPoint 是 Mac OS 类型。我认为它没有在 iOS 中定义。在 iOS 中,您可以将 NSPoint 转换为 CGPoint:

//Probably not valid in iOS because NSPoint isn't defined, but is shows a variable
NSPoint somePoint = MakePoint(273,534); 

//Cast an NSPoint to a CGPoint in order to get at it's values...
viewTwo.frame=CGRectMake(273,534,((CGPoint)somePoint).x,((CGPoint)somePoint).y);
于 2014-12-19T13:38:53.547 回答
4

假设你有这个:

NSValue *point = [NSValue valueWithCGPoint:CGPointMake(273, 534)];

它将在控制台中输出如下:

NSPoint: {273,534}

所以你可以像这样创建 CGRect

viewTwo.frame=CGRectMake([point CGPointValue].x, [point CGPointValue].y, someValue, someValue);
于 2014-12-18T14:43:25.337 回答
0

您是否在某处缺少 Foundation 框架的导入?在 Xcode 6+ 中创建的项目中,没有默认的预编译头文件,因此必须手动导入更多框架头文件;虽然 NSPoint 应该可以正常工作。

于 2014-12-18T14:44:17.747 回答
0

也许是这样:

NSPoint somePoint; 
// Assuming this point got its value from some function.
viewTwo.frame = CGRectMake(somePoint.x, somePoint.y, myWidth, myHeight);
于 2014-12-18T14:32:10.200 回答