Jack K
Jack K

Reputation: 483

NSImageView Center?

I am trying to make Pong for Mac. For the ball bounce code, I am trying to access the ball's center. The ball is a NSImageView. For iOS programming, I can just access a UIImageView's center by calling

ball.center = ...;

How can I do this with an NSImageView. Sorry if this is dumb, I'm new to Cocoa programming.

Upvotes: 0

Views: 838

Answers (1)

Paul.s
Paul.s

Reputation: 38728

You could add a simple category like:

- (void)ps_setCenter:(NSPoint)center;
{
    [self setFrameOrigin:NSMakePoint(center.x - (self.frame.size.width * 0.5f),
                                     center.y - (self.frame.size.height * 0.5f))];
    [self setNeedsDisplay:YES];
}

Upvotes: 3

Related Questions