起因:iOS13 后,UIModalPresentationFullScreen 模式,會導致原 View 的 frame 改變,非常詭異,所以就需要定位 frame 的變化,然而 View 的 frame 又和常規(guī)的方式不太一樣,研究發(fā)現(xiàn),才有以下的實現(xiàn)。
上代碼
@implementation UIView (MGPrivate)
- (void)setFrame:(CGRect)frame
{
if (self.tag == 10000)
{
}
//設置frame時并沒有考慮到仿射坐標變換屬性transform。
float w = frame.size.width;
float h = frame.size.height;
self.bounds = CGRectMake(0, 0, w, h);
float x = frame.origin.x + self.bounds.size.width * self.layer.anchorPoint.x;
float y = frame.origin.y + self.bounds.size.height *
self.layer.anchorPoint.y;
self.center = CGPointMake(x, y);
}
@end
關鍵是重寫 View frame 的實現(xiàn)方法,其他就是通過 tag 定位到我們需要的 view。
注意: 真實的 frame 實現(xiàn)并不是如此,這里只是為了定位 frame 的變化。