第一段代码:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}];
NSLog(@"%@", self.scrollView);
结果是:<UIScrollView: 0x7fcae504ba00; frame = (0 0; 0 0);
第二段代码:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}];
// 延迟0.1秒后获取frame
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"%@", self.scrollView);
});
结果是:<UIScrollView: 0x7fad83820a00; frame = (0 0; 375 667);
问:
为什么延迟0.1秒后就能获取到正确的frame了?
推荐一篇 博文 ,讲得挺不错的!