If you want it fixed in place, I would try something like this:
NSRect viewFrame = [[theScollView contentView] frame];
to get the interior size of the view, then set the corner of the rectangle like this:
theRectangle.origin.x = ( ( viewFrame.size.width - theRectangle.size.width ) / 2.0 ) + viewFrame.origin.x;