檢查這個問題的答案:Xcode6, iOS8 and (void)layoutSubviews
真的layoutSubviews不叫了對的UILabel iOS8上,蘋果不希望任何人使用它作爲上海華。
我正在使用ReactiveCocoaLayout,因此可以通過訂閱rcl_frameSignal或rcl_boundsSignal來完成。
-(void)awakeFromNib { [ self.rcl_boundsSignal subscribeNext: ^(NSValue* boundsValue) { //layout changed } ]; }
Or you can use simple KVO to know when frame has been changed:
-(void)dealloc
{
[ self removeObserver: self forKeyPath: @"layer.bounds" ];
}
-(void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context
{
if ([ keyPath isEqualToString: @"layer.bounds" ])
{
//layoutSubviews
}
else
{
[ super observeValueForKeyPath: keyPath
ofObject: object
change: change
context: context ];
}
}
-(void)awakeFromNib
{
[ self addObserver: self
forKeyPath: @"layer.bounds"
options: NSKeyValueObservingOptionNew
context: 0 ];
}
似乎問題已在iOS 8.1 beta版本中修復。 – ABC1 2014-09-30 02:45:41