简体   繁体   中英

Adjust NSWindow height from bottom?

Suppose I have a window named mWindow . To increase the height I would do this to the frame:

NSRect windowFrame = [mWindow frame]; 
windowFrame.size.height += 100.0f;
[mWindow setFrame:windowFrame];

However, this increase the height of the top of the window, not the bottom. How can I make it add more window at the bottom instead of the top?

Because of the way coordinates work in Cocoa, you'll have to do some extra steps to make this work:

NSRect windowFrame = [mWindow frame];
windowFrame.size.height += 100;
windowFrame.origin.y -= 100;
[mWindow setFrame:windowFrame display:YES];

Alternatively, you can use the setFrameOrigin: or setFrameTopLeftPoint: methods of NSWindow.

I use this snippet. You have to adjust origin.y according to offset

func change(height: CGFloat) {
  var frame = window.frame
  let offset = height - frame.size.height
  frame.size.height += offset
  frame.origin.y -= offset

  window.setFrame(rect, display: true)
}

您可以随时相应地调整原点,即将其调高并向下移动。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM