仿QQ动态界面导航条渐变

仿QQ动态界面导航条渐变_第1张图片
仿QQ动态界面导航条渐变_第2张图片




1.QQ动态界面隐藏了navigation bar 和statusbar

隐藏导航条和状态栏

2.附上代码


//  FiveViewController.h//  iOS_导航透明度变化实现////  Created by 密码123 on 16/12/15.//  Copyright © 2016年 高宇. All rights reserved.//#import@interface FiveViewController : UIViewController

@end

/**********************/

////  FiveViewController.m//  iOS_导航透明度变化实现////  Created by 密码123 on 16/12/15.//  Copyright © 2016年 高宇. All rights reserved.//#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height#import "FiveViewController.h"@interface FiveViewController ()@property (strong, nonatomic) UITableView *tableView;

@property (strong, nonatomic) UIView *barView;

@property (strong, nonatomic) UIButton *addBtn;

@end

@implementation FiveViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor=[UIColor whiteColor];

self.navigationController.navigationBarHidden=YES;

[[UIApplication sharedApplication]setStatusBarHidden:YES];

[self.view addSubview:self.tableView];

[self.view addSubview:self.barView];

[self.barView addSubview:self.addBtn];

}

- (UITableView *)tableView

{

if (!_tableView) {

_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];

_tableView.delegate = self;

_tableView.dataSource = self;

_tableView.tableFooterView = nil;

_tableView.backgroundColor = [UIColor whiteColor];

}

return _tableView;

}

-(UIView *)barView

{

if (!_barView)

{

_barView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];

}

return _barView;

}

-(UIButton *)addBtn

{

if (!_addBtn) {

_addBtn=[UIButton buttonWithType:UIButtonTypeCustom];

_addBtn.frame=CGRectMake(SCREEN_WIDTH-60, 10, 50, 44);

[_addBtn setTitle:@"添加" forState:UIControlStateNormal];

[_addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];

}

return _addBtn;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark  - tableViewDelegate代理方法

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 30;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *rid=@"cell";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:rid];

if(cell==nil){

cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rid];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.contentView.backgroundColor = [UIColor purpleColor];

}

cell.textLabel.text = [NSString stringWithFormat:@"tableView的第%ld个cell",indexPath.row];

return cell;

}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

return 0.00000001;

}

- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

return 0.000000001;

}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

[self.navigationController popViewControllerAnimated:YES];

}

#pragma mark  - scrollViewDelegate代理方法

-(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView

{

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

return YES;

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

UIColor *color = [UIColor colorWithRed:26.0/255 green:167.0/255 blue:244.0/255 alpha:1.0];

CGFloat offsetY = scrollView.contentOffset.y;

if (offsetY>=200.0)

{

self.addBtn.backgroundColor=[UIColor whiteColor];

[self.addBtn setTitleColor:color forState:UIControlStateNormal];

}

else

{

[self.addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

self.addBtn.backgroundColor=[UIColor clearColor];

}

NSLog(@"----  %f--",offsetY);

if (offsetY > 0)

{

CGFloat alpha = 1 - ((200 - offsetY) / 200);

//        self.navigationController.navigationBar.backgroundColor = [color colorWithAlphaComponent:alpha];

//        self.navigationController.navigationBar.tintColor=[color colorWithAlphaComponent:alpha];

self.barView.backgroundColor=[color colorWithAlphaComponent:alpha];

}

else

{

//        //        self.navBar.backgroundColor = [color colorWithAlphaComponent:0];

//        self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];

self.barView.backgroundColor=[color colorWithAlphaComponent:0];

}

//让tableview拖动一段距离就不能拖动

if (offsetY<=-100) {

//        self.tableView.scrollEnabled=NO;

[self.tableView setContentOffset:CGPointMake(0, -100)];

}

}

#pragma mark - 点击事件

-(void)addBtnAction:(id)sender

{

NSLog(@"addBtnAction");

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end



3.其他渐变效果

几句话实现导航栏透明渐变(iOS)


导航栏透明度变化实现

你可能感兴趣的:(仿QQ动态界面导航条渐变)