开发者

Position of window in Cocoa

开发者 https://www.devze.com 2023-01-15 10:54 出处:网络
i have simple question: How to get position of window on screen in cocoa? I try using frame from NSWindow but in result i have x and y of window always 0, but my win开发者_C百科dow isn\'t on this posi

i have simple question: How to get position of window on screen in cocoa? I try using frame from NSWindow but in result i have x and y of window always 0, but my win开发者_C百科dow isn't on this position.

Best regards Chudziutki


How to get position of window on screen in cocoa?

Send it a frame message and look at the result's origin member.

I try using frame from NSWindow but in result i have x and y of window always 0, but my window isn't on this position.

You forgot to hook up the outlet to your window, so you're sending that frame message to nil.

Frankly, it's surprising that the frame rectangle makes any sense at all instead of being a geometrically-impossible random set of numbers. Messages to nil return 0 for scalar types, such as pointers and single numbers, but a message that returns a structure (such as a rectangle) is not guaranteed to return anything.

Or you're talking to the wrong window—perhaps you created one in a nib and then created another one in code.

0

精彩评论

暂无评论...
验证码 换一张
取 消