【问题标题】:How to receive notification when an NSView is moved如何在移动 NSView 时接收通知
【发布时间】:2016-10-03 15:28:33
【问题描述】:
如何在 NSView 移动时接收通知/回调 - 或者在 NSViewController 移动时。
我看到有 NSWindow (NSWindowDidMoveNotification) 的方法,但我不知道如何使用 NSView 或 NSViewController 处理它。
我知道 NSView 有一个 NSWindow 并且这就是具有“坐标”的东西,但我不确定如何子类化这个 NSWindow 来覆盖 move 方法。
【问题讨论】:
标签:
macos
user-interface
nsview
【解决方案1】:
我发现了。像这样添加一个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(frameDidChange:)
name:NSViewFrameDidChangeNotification
object:self.view];
还有这样的选择器:
- (void)frameDidChange:(NSNotification*)notification {
NSView* view = [notification object];
...
}