TigerCoding
TigerCoding

Reputation: 8720

How do I scale CGPoint based on CGSize changes?

I have CGRect with a default (square) size. The size is adjustable based on the view controllers needs, but always maintains a square proportion.

If I want to plot a point within the rect, but the scale of the rect is variable up and down in size, how would I calculate the new point position based on the change in rect size?

// in a UIView object, values always positive
- (CGPoint)convertPointToViewSizeScale:(CGPoint)point
{
    CGSize defaultSize = kViewSizeDefault;
    CGSize currentSize = self.frame.size;
    // ...
    return point;
}

Upvotes: 1

Views: 3904

Answers (1)

rob mayoff
rob mayoff

Reputation: 386038

point.x *= currentSize.width / defaultSize.width;
point.y *= currentSize.height / defaultSize.height;

Upvotes: 3

Related Questions