美文网首页
iOS UIView Frame 剖析

iOS UIView Frame 剖析

作者: wnido | 来源:发表于2019-10-29 09:42 被阅读0次

    起因:iOS13 后,UIModalPresentationFullScreen 模式,会导致原 View 的 frame 改变,非常诡异,所以就需要定位 frame 的变化,然而 View 的 frame 又和常规的方式不太一样,研究发现,才有以下的实现。

    上代码

    @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 的实现方法,其他就是通过 tag 定位到我们需要的 view。

    注意: 真实的 frame 实现并不是如此,这里只是为了定位 frame 的变化。

    相关文章

      网友评论

          本文标题:iOS UIView Frame 剖析

          本文链接:https://www.haomeiwen.com/subject/kzkwvctx.html