当设置个人热点,状态栏变高造成布局出错的处理

1、bug修改

UIView *bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, bottomBarHeight)];

    bottomBarView.backgroundColor = [UIColor whiteColor];

    bottomBarView.bottom = self.view.bottom;

    bottomBarView.tag = kDIYBottomBarViewTag;

    [self.view addSubview:bottomBarView];

之前是根据bottom确定的bottomBarView的竖直位置。

而:self.view.bottom = self.view.frame.origin.y + self.view.frame.size.height;

那相当于:bottomBarView.bottom =  self.view.frame.origin.y + self.view.frame.size.height;

相当于:bottomBarView.frame = CGRectMack(0, self.view.frame.origin.y + self.view.frame.size.height-bottomBarHeight,self.view.width, bottomBarHeight);

问题就在于,self.view是bottomBarView的父视图,[self.view addSubview:bottomBarView]的话,正常bottomBarView的frame应该为(0,self.view.heught-bottomBarView.height,self.view.width,bottomBarView.height)

bottomBarHeight == bottomBarView.height;

这样self.view.frame.origin.y是多出来的,当开启个人热点或来电话是,statusBar的高度由之前的20变成40,self.view.frame.origin.y由之前的0变成20,这样bottomBarView就整体下移了20. self.view.height减少了20;

这是改过的代码:

UIView *bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - bottomBarHeight, self.view.width, bottomBarHeight)];

    bottomBarView.backgroundColor = [UIColor whiteColor];

    //bottomBarView.bottom = self.view.bottom;

    bottomBarView.tag = kDIYBottomBarViewTag;

    [self.view addSubview:bottomBarView];

总结:当两个视图存在父子关系是,最好不要用bottom属性传值,因为他们的相对坐标原点不同,子视图的(0,0)位置是父视图的(origin.x,origin.y)位置,bottom的计算就存在误差。(frame.origin.y的改变)

2、造成视图下移的其它原因:

 SCREEN_HEIGHT的使用,当个人热点形成,statusBar变为40,self.view.height和self.view.bounds.height都减少20,而此时再用SCREEN_HEIGHT为基准计算视图高度或位置时,因为SCREEN_HEIGHT的大小并没有改变,所以造成适配偏差。


备注:

1、

-(CGFloat)bottom {

    return self.frame.origin.y + self.frame.size.height;


}

2、

#define SCREEN_HEIGHT (IsPortrait ? MAX(([UIScreen mainScreen].bounds.size.width), ([UIScreen mainScreen].bounds.size.height)) : MIN(([UIScreen mainScreen].bounds.size.width), ([UIScreen mainScreen].bounds.size.height)))



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值