iPad 和iPhone用同一套代码打包适配遇到的问题

1.项目需求,进入之后导航栏透明,header是一张图片,完全展示出来,随着页面向上滑动,导航栏透明度逐渐减小,当滑动的位置偏移超过固定值时,导航栏出现.

代码实现:

1.

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self requestData];
 
     [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
      //去掉导航条线面的黑线
     [self.navigationBar setShadowImage:[UIImage new]];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self setLeftButtonWithImage:@"icon_back_white" highlightedImage:nil target:self action:@selector(onBack)];
    [self setRightButtonWithImage:@"icon_share_white" highlightedImage:nil target:self action:@selector(clickShare)];

    CGRect frame = self.navigationController.navigationBar.frame;
    self.alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, frame.size.width, frame.size.height+20)];
    self.alphaView.backgroundColor = [UIColor whiteColor];
    self.alphaView.alpha = 0.0;
    self.alphaView.userInteractionEnabled = NO;
 
   [self.navigationController.navigationBar insertSubview: self.alphaView atIndex:0];
    
    self.scrollView.backgroundColor = [UIColor colorWithHexString:@"F0F0F0"];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    UIImage *backImage = [[UIImage imageWithColor:[UIColor whiteColor]] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
     [self.navigationBar setBackgroundImage:backImage forBarMetrics:UIBarMetricsDefault];
     [self.navigationBar setShadowImage:nil];
}

2.出现问题:

iPhone效果正常;在iPad Air2  系统版本12.2模拟器上好使,在iPad Air2 系统版本:11.0.3上失效.

真机图层显示:

模拟器显示:

3:修改;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self requestData];

    if (DEVICE_IS_IPAD) {
        UIImage *backImage = [[UIImage imageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:(_offset / 64) >0.99 ?0.99 :(_offset / 64)]] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
        [self.navigationController.navigationBar setBackgroundImage:backImage forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    } else {
   
            [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
            //去掉导航条线面的黑线
            [self.navigationBar setShadowImage:[UIImage new]];
        
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值