1
我試圖更新我的視圖時,其界限更改。我的觀點是在其超視圖中使用自動佈局。界限總是爲零與自動佈局
這是我的觀察範圍的代碼:
public override init() {
super.init()
self.addObserver(self, forKeyPath: "bounds", options: .New, context: nil)
}
public override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
NSLog("[SkewedSplitView]: observer: %fx%f, %f:%f", self.bounds.width, self.bounds.height, self.bounds.origin.x, self.bounds.origin.y)
}
輸出:
2014年12月2日12:35:35.018 XXX [7365:2001261] [SkewedSplitView]:觀察者: 0.000000x0.000000,0.000000:0.000000
我想即使Swits觀察家:
override public var bounds: CGRect {
didSet {
NSLog("[SkewedSplitView]: bounds: %fx%f, %f:%f", self.frame.width, self.frame.height, self.frame.origin.x, self.frame.origin.y)
}
}
輸出:
2014年12月2日12:35:35.012 XXX [7365:2001261] [SkewedSplitView]:界限: 0.000000x0.000000,0.000000:0.000000
兩人都只被稱爲一次。 繼承人我的代碼,規定了該視圖(使用製圖):
let betters = SkewedSplitView()
betters.backgroundColor = UIColor.greenColor()
self.addSubview(betters)
constrain(betters, friends) { (betters, friends) in
betters.bottom == friends.top - 3
betters.leading == betters^.leading
betters.trailing == betters^.trailing
betters.height == 40
}
屏幕上的觀點奠定了就好了,有正確的幀。
這些都不在UIView – 2014-12-02 13:22:08