仿QQ動態(tài)界面導航條漸變




1.QQ動態(tài)界面隱藏了navigation bar 和statusbar

隱藏導航條和狀態(tài)欄

2.附上代碼


//? FiveViewController.h//? iOS_導航透明度變化實現(xiàn)////? Created by 密碼123 on 16/12/15.//? Copyright ? 2016年 高宇. All rights reserved.//#import@interface FiveViewController : UIViewController

@end

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

////? FiveViewController.m//? iOS_導航透明度變化實現(xiàn)////? 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.其他漸變效果

幾句話實現(xiàn)導航欄透明漸變(iOS)


導航欄透明度變化實現(xiàn)

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末时捌,一起剝皮案震驚了整個濱河市怀愧,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌惨缆,老刑警劉巖东羹,帶你破解...
    沈念sama閱讀 218,607評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件剂桥,死亡現(xiàn)場離奇詭異,居然都是意外死亡属提,警方通過查閱死者的電腦和手機权逗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來冤议,“玉大人斟薇,你說我怎么就攤上這事∷∷幔” “怎么了堪滨?”我有些...
    開封第一講書人閱讀 164,960評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蕊温。 經(jīng)常有香客問我袱箱,道長,這世上最難降的妖魔是什么义矛? 我笑而不...
    開封第一講書人閱讀 58,750評論 1 294
  • 正文 為了忘掉前任发笔,我火速辦了婚禮,結果婚禮上凉翻,老公的妹妹穿的比我還像新娘了讨。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 67,764評論 6 392
  • 文/花漫 我一把揭開白布量蕊。 她就那樣靜靜地躺著铺罢,像睡著了一般。 火紅的嫁衣襯著肌膚如雪残炮。 梳的紋絲不亂的頭發(fā)上韭赘,一...
    開封第一講書人閱讀 51,604評論 1 305
  • 那天,我揣著相機與錄音势就,去河邊找鬼泉瞻。 笑死,一個胖子當著我的面吹牛苞冯,可吹牛的內(nèi)容都是我干的袖牙。 我是一名探鬼主播,決...
    沈念sama閱讀 40,347評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼舅锄,長吁一口氣:“原來是場噩夢啊……” “哼鞭达!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起皇忿,我...
    開封第一講書人閱讀 39,253評論 0 276
  • 序言:老撾萬榮一對情侶失蹤畴蹭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后鳍烁,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體叨襟,經(jīng)...
    沈念sama閱讀 45,702評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,893評論 3 336
  • 正文 我和宋清朗相戀三年幔荒,在試婚紗的時候發(fā)現(xiàn)自己被綠了糊闽。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,015評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡爹梁,死狀恐怖右犹,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情姚垃,我是刑警寧澤傀履,帶...
    沈念sama閱讀 35,734評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站莉炉,受9級特大地震影響钓账,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜絮宁,卻給世界環(huán)境...
    茶點故事閱讀 41,352評論 3 330
  • 文/蒙蒙 一梆暮、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧绍昂,春花似錦啦粹、人聲如沸偿荷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽跳纳。三九已至,卻和暖如春贪嫂,著一層夾襖步出監(jiān)牢的瞬間寺庄,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評論 1 270
  • 我被黑心中介騙來泰國打工力崇, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留斗塘,地道東北人。 一個月前我還...
    沈念sama閱讀 48,216評論 3 371
  • 正文 我出身青樓亮靴,卻偏偏與公主長得像馍盟,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子茧吊,可洞房花燭夜當晚...
    茶點故事閱讀 44,969評論 2 355

推薦閱讀更多精彩內(nèi)容