0
有没有更好的方法来观察NSScrollView - > NSClipView框架/边界的变化? 这是的OBJ-C代码翻译成斯威夫特:Swift NSScrollView更好NSViewBoundsDidChangeNotification观察?
public override init(frame frameRect: NSRect) {
self.contentView.postsFrameChangedNotifications = true;
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "frameDidChange:",
name: NSViewFrameDidChangeNotification,
object: self.contentView)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(
self,
name: NSViewFrameDidChangeNotification,
object: self.contentView)
}
它的工作原理,但我不希望使用NSNotificationCenter。我想在NSClipView使用frame属性观察:
class MyClipView: NSClipView {
...
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
self.postsFrameChangedNotifications = true;
}
override var frame: CGRect {
didSet {
println("Did set frame")
}
}
}
但didSet被称为初始化后只有2次并封闭NSScrollView滚动时,它永远不会被调用。看起来苹果正在使用内部方法来更改框架而不调用框架属性?
同样代表NSViewBoundsDidChangeNotification和bounds属性。
算了笔以覆盖帧,setFrameOrigin,setFrameSize。没有一个被调用,多于一次。它们在初始化后被调用的顺序是:setFrameOrigin,setFrameSize,frame。我想这对边界是一样的。滚动过程中不调用方法/属性。 – 2015-02-11 22:06:51