本文介绍了调整窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的操作系统应用程序,但我无法在任何地方找到如何执行调整大小事件。

I'm creating a simple OS app but I cannot find anywhere how to take the resize event.

让我们假设我打印新的宽度和高度,我有这个控制器:

Let's assume that I wanna print the new width and height and I have this controller:

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    override var representedObject: AnyObject? {
        didSet {
            // Update the view, if already loaded.
        }
    }

}

必须添加?谢谢。

我的问题与。因为我的View必须扩展 NSViewController ,而不是 NSWindowController 。这在他的回答他没有解释什么 windowWillResize 必须完全返回

My question is not the same as Listen for window resize event in Swift / Objective-C. Since my View have to extend NSViewController and not NSWindowController. This in his answer he did not explain what windowWillResize has to return exactly

推荐答案

您需要在某处实现 NSWindowDelegate ,并将窗口的委托设置为该对象。如果你愿意,你可以实现这个代码在你的视图控制器。

You need to implement NSWindowDelegate somewhere, and set the window's delegate to that object. If you want, you could implement this code in your view controller.

class ViewController: NSViewController, NSWindowDelegate {
    override func viewWillAppear() {
        self.view.window.delegate = self
    }

    func windowWillResize(sender: NSWindow, toSize frameSize: NSSize) -> NSSize {
        // Your code goes here
    }

    func windowDidResize(notification: NSNotification) {
        // Your code goes here
    }
}

这篇关于调整窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:45