调用[super layoutSubviews]的正确方法是什么? [英] What is the correct way to call [super layoutSubviews]?
本文介绍了调用[super layoutSubviews]的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在iOS版Facebook SDK中看到,他们在layoutSubviews
方法的结尾而不是在layoutSubviews
方法的开头调用[super layoutSubviews];
.
I just saw in the Facebook SDK for iOS that they call [super layoutSubviews];
at the end and not at the beginning of the layoutSubviews
method.
据我所知,我们应该始终作为第一行. 可以通过其他方式实现它导致任何意外的UI行为吗?
As far as I know, we should always do it as the first line. Can implementing it a different way cause any unexpected UI behavior?
- (void)layoutSubviews
{
CGSize size = self.bounds.size;
CGSize longTitleSize = [self sizeThatFits:size title:[self _longLogInTitle]];
NSString *title = (longTitleSize.width <= size.width ?
[self _longLogInTitle] :
[self _shortLogInTitle]);
if (![title isEqualToString:[self titleForState:UIControlStateNormal]]) {
[self setTitle:title forState:UIControlStateNormal];
}
[super layoutSubviews];
}
推荐答案
查看全文