IOS只改变父视图的的透明度,不会改变子View的透明度

//正在滚动

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

 

    float offset_Y = scrollView.contentOffset.y;

    NSLog(@"%f",scrollView.contentOffset.y);

    UIView *barView = [self.navigationController.view viewWithTag:1000];

    if (offset_Y == -20) {

        //colorWithAlphaComponent 只改变父视图的的透明度,不会改变子View的透明度

        barView.backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent:0.0];

    }else if(offset_Y >= 160){

        barView.alpha = 1.0;

    }else{

        barView.backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent:(offset_Y) / 160];

    }

        

}

原文地址:https://www.cnblogs.com/ios988/p/5169605.html