Skip navigation.
 
mlRe: NSWindow Centering Problem
FROM : Jean-Daniel Dupas
DATE : Wed May 07 21:56:06 2008

AFAK, there is no other method than center to center the window on 
screen, but doing one that really center the window is not very 
difficult.

@implementation NSWindow (TrueCenter)

- (void)trueCenter {
   NSRect frame = [self frame];
   NSRect *screen = [[self screen] frame];
   frame.origin.x = (screen.size.width - frame.size. width) / 2;
   frame.origin.y = (screen.size.height - frame.size.height) / 2;
   [self setFrameOrigin:frame.origin];
}

@end


Le 7 mai 08 à 21:42, Philip Bridson a écrit :

> Ok very funny. Just to clarify that I had already read the 
> documentation, otherwise I would not even be able to get the window 
> to display on the screen  - but thanks for pointing it out. However, 
> I probably worded the question wrong, so I will re-phrase it: If by 
> using [MyWindow center] the window does not actually center itself 
> in the middle of the screen is there a method available so that it 
> will actually be in the center of the screen?
>
> I am open to suggestions and directions to where I can find the 
> information but sarcasm is not funny and not helpful and therefore 
> if you cannot construct a helpful sentence then don't reply.
>
> Phil.
>
> On 7 May 2008, at 20:31, Sean McBride wrote:
>

>> On 5/7/08 3:06 PM, Andy Lee said:
>>

>>> On May 7, 2008, at 2:59 PM, Philip Bridson wrote:

>>>> Can anyone tell me why when I use [MyWindow center] the window ends
>>>> up about an inch from the top of the screen? I thought this method
>>>> is meant to center the window. Is there something I am doing wrong?

>>>
>>> Only not reading the documentation. :)
>>>

>>>> center
>>>> Sets the receiver's location to the center of the screen.
>>>>
>>>> - (void)center
>>>>
>>>> Discussion
>>>> The receiver is placed exactly in the center horizontally and
>>>> somewhat above center vertically. [...]

>>
>> No doubt roughly at the golden ratio, for aesthetic pleasantness:
>> <http://en.wikipedia.org/wiki/Golden_ratio>
>>
>> --
>> ____________________________________________________________
>> Sean McBride, B. Eng                <email_removed>
>> Rogue Research                        www.rogue-research.com
>> Mac Software Developer              Montréal, Québec, Canada
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>
>> This email sent to <email_removed>

>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
>

Related mailsAuthorDate
mlNSWindow Centering Problem Philip Bridson May 7, 20:59
mlRe: NSWindow Centering Problem Andy Lee May 7, 21:06
mlRe: NSWindow Centering Problem Jean-Daniel Dupas May 7, 21:11
mlRe: NSWindow Centering Problem Andy Lee May 7, 21:25
mlRe: NSWindow Centering Problem Sean McBride May 7, 21:31
mlRe: NSWindow Centering Problem Philip Bridson May 7, 21:42
mlRe: NSWindow Centering Problem Gregory Weston May 7, 21:51
mlRe: NSWindow Centering Problem Sean McBride May 7, 21:52
mlRe: NSWindow Centering Problem Andy Lee May 7, 21:52
mlRe: NSWindow Centering Problem Jean-Daniel Dupas May 7, 21:56
mlRe: NSWindow Centering Problem Philip Bridson May 7, 22:05
mlRe: NSWindow Centering Problem Andy Lee May 7, 22:30
mlRe: NSWindow Centering Problem Andy Lee May 7, 22:36