iOS Masonry布局获取Frame

方法1


[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}];
// 先调用superView的layoutIfNeeded方法再获取frame
[self.view layoutIfNeeded];
NSLog(@"%@", self.scrollView);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

打印结果

= (0 0; 375 667);
  • 1

方法2

[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}];
// 0.1秒后获取frame, 设置为0秒也可以获取,具体参考链接
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    NSLog(@"%@", self.scrollView);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

打印结果

= (0 0; 375 667);

你可能感兴趣的:(iOS Masonry布局获取Frame)