iOS使用Autolayout后,如何更新frame

答案:调用下layoutIfNeeded后,系统会触发更新,但不一定保证何时能更新。

如果要强制获得Autolayout的frame可以给UIView增加如下的Category方法:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- (CGFloat)my_layoutHeight {
return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
- (CGFloat)my_layoutWidth {
return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].width;
}
- (CGFloat)my_layoutHeight { return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; } - (CGFloat)my_layoutWidth { return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].width; }
- (CGFloat)my_layoutHeight {
    return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}

- (CGFloat)my_layoutWidth {
    return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].width;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *