Converting NSpoint and passing the values in to CGRectMake

3.9k views Asked by At

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

There are 4 answers

0
Duncan C On BEST ANSWER

NSPoint is a Mac OS type. I don't think it's defined in iOS. In iOS you can just cast an NSPoint to a 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);
1
larod On

Maybe this:

NSPoint somePoint; 
// Assuming this point got its value from some function.
viewTwo.frame = CGRectMake(somePoint.x, somePoint.y, myWidth, myHeight);
1
Ratha Hin On

Assume that you have this:

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

It will output like this in console:

NSPoint: {273,534}

So you can create CGRect like this

viewTwo.frame=CGRectMake([point CGPointValue].x, [point CGPointValue].y, someValue, someValue);
4
Jannis On

Are you missing an import for the Foundation framework somewhere? In projects created in Xcode 6+, there's no default precompiled header so more framework headers have to be imported manually; although NSPoint should just work fine.