您的位置:首页 > 其它

edgesForExtendedLayout对子vc的view的影响

2015-12-23 10:00 411 查看
将vc的edgesForExtendedLayout设为none后,

如果顶部有导航栏,且显示状态栏。

vc.view的坐标原点从0会变为64,而且高度会相应的减少64。

而且,如果在vc在想用其它vc的view,

在设了此view的frame后,此view的高度竟然也后自动减少64,但其y值不会变。

经检查,是因为后加入的vc的view的默认的autoresizingMask值的原因,

其值是18转为2进制是10010,

也就是UIViewAutoresizingFlexibleWidth和UIViewAutoresizingFlexibleHeight,

而普通的view的autoresizingMask是0。

所以,在根vc的view因为edgesForExtendedLayout设为UIRectEdgeNone后,会将高度减少64,则

子vc的view就因为其autoresizingMask值的原因,高度也跟着减少了64。

所以解决方案就是

方式一、子vc的view用相对定位。

方式二、将子vc的view的autoresizingMask设为UIViewAutoresizingNone。

参考一,取autoResizing 的值:

UIViewAutoresizing autoResizing = testView.autoresizingMask;

    if ( autoResizing & UIViewAutoresizingFlexibleWidth){

        NSLog(@"选中了UIViewAutoresizingFlexibleWidth");

    }

    

    if ( autoResizing & UIViewAutoresizingFlexibleHeight){

        NSLog(@"选中了UIViewAutoresizingFlexibleWidth");

    }

参考二,UIViewAutoresizing的各项值。

typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {

    UIViewAutoresizingNone                 = 0,

    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,

    UIViewAutoresizingFlexibleWidth        = 1 << 1,

    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,

    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,

    UIViewAutoresizingFlexibleHeight       = 1 << 4,

    UIViewAutoresizingFlexibleBottomMargin = 1 << 5

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息