一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - IOS - iOS實現知乎和途家導航欄漸變的文字動畫效果

iOS實現知乎和途家導航欄漸變的文字動畫效果

2021-01-27 16:08iOS開發網 IOS

這篇文章給大家分享了利用iOS實現知乎和途家導航欄漸變的文字動畫效果,有需要的朋友們可以參考借鑒。下面來一起看看。

效果圖如下

iOS實現知乎和途家導航欄漸變的文字動畫效果

分析如下:

     1.導航欄一開始是隱藏的,隨著scrollview滾動而漸變

     2.導航欄左右兩邊的navigationitem是一直顯示的

     3.導航欄參考了途家app,使用了毛玻璃效果,背景是一張圖片

     4.下拉放大圖片效果

     5.title文字動畫效果

通過簡單分析,系統的導航欄實現以上效果有點困難,直接自定義一個假的導航欄更容易點

分布拆解實現以上效果

一.下拉放大header圖片

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
- (void)viewdidload {
 [super viewdidload];
 [self.view addsubview:self.scaleimageview];
 
 // 設置展示圖片的約束
 [_scaleimageview mas_makeconstraints:^(masconstraintmaker *make) {
  make.top.mas_equalto(0);
  make.left.equalto(self.view.mas_left);
  make.right.equalto(self.view.mas_right);
  make.height.mas_equalto(kheardh);
 }];
}
 
// tableview懶加載
-(uitableview *)tableview{
 if(_tableview == nil){
  _tableview = [[uitableview alloc]initwithframe:self.view.bounds style:uitableviewstyleplain];
  _tableview.contentinset = uiedgeinsetsmake(kheardh-35, 0, 0, 0);
  _tableview.delegate = self;
  _tableview.datasource = self;
  _tableview.separatorstyle = uitableviewcellseparatorstylenone;
 }
 return _tableview;
}
 
// 圖片的懶加載
- (uiimageview *)scaleimageview
{
 if (!_scaleimageview) {
  _scaleimageview = [[uiimageview alloc] init];
  _scaleimageview.contentmode = uiviewcontentmodescaleaspectfill;
  _scaleimageview.clipstobounds = yes;
  _scaleimageview.image = [uiimage imagenamed:@"666"];
 
 }
 return _scaleimageview;
}
 
// 導航欄高度
#define knavbarh 64.0f
// 頭部圖片的高度
#define kheardh 260
#pragma mark - uiscrollviewdelegate
- (void)scrollviewdidscroll:(uiscrollview *)scrollview {
 
 // 計算當前偏移位置
 cgfloat offsety = scrollview.contentoffset.y;
 cgfloat delta = offsety - _lastoffsety;
 dlog(@"delta=%f",delta);
 dlog(@"offsety=%f",offsety);
 cgfloat height = kheardh - delta;
 if (height < knavbarh) {
  height = knavbarh;
 }
 
 [_scaleimageview mas_updateconstraints:^(masconstraintmaker *make) {
  make.height.mas_equalto(height);
 }];
}

二.導航欄左右兩邊的navigationitem是一直顯示的

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- (void)viewdidload {
 [super viewdidload];
 
 // 直接添加到控制器的view上面,注意添加順序,在添加導航欄之后,否則會被遮蓋住
 [self confignavigationbar];
}
 
- (void)confignavigationbar{
 //左邊返回按鈕
 uibutton *backbtn = [[uibutton alloc]init];
 backbtn.frame = cgrectmake(0, 20, 44, 44);
 [backbtn setimage:[uiimage imagenamed:@"special_back"] forstate:uicontrolstatenormal];
 [backbtn addtarget:self action:@selector(back) forcontrolevents:uicontroleventtouchupinside];
 
 //右邊分享按鈕
 uibutton *shartbtn = [[uibutton alloc]init];
 shartbtn.frame = cgrectmake(screenwidth-44, 20, 44, 44);
 [shartbtn setimage:[uiimage imagenamed:@"special_share"] forstate:uicontrolstatenormal];
 [shartbtn addtarget:self action:@selector(sharebtnclick) forcontrolevents:uicontroleventtouchupinside];
 [self.view addsubview:backbtn];
 [self.view addsubview:shartbtn];
}
// 返回
-(void)back{
 [self.navigationcontroller popviewcontrolleranimated:yes];
}

三.自定義導航欄及毛玻璃效果及title文字動畫效果

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// 隱藏系統導航欄
- (void)viewwillappear:(bool)animated{
 [super viewwillappear:animated];
 self.navigationcontroller.navigationbar.hidden = yes;
}
 
- (void)viewdidload {
 [super viewdidload];
 
 self.navigationcontroller.navigationbar.hidden = yes;
 self.lastoffsety = - kheardh+35;
 [self.view addsubview:self.tableview];
 self.tableview.backgroundcolor = [uicolor clearcolor];
 [self.view addsubview:self.navigationview];
 self.navigationcontroller.navigationbar.barstyle = uibarstyleblack;
}
 
 
// 自定義導航欄
-(uiview *)navigationview{
 
 if(_navigationview == nil){
  _navigationview = [[uiview alloc]init];
  _navigationview.frame = cgrectmake(0, 0, screenwidth, knavbarh);
  _navigationview.backgroundcolor = [uicolor clearcolor];
  _navigationview.alpha = 0.0;
 
  //添加子控件
  [self setnavigationsubview];
 }
 return _navigationview;
}
 
// 注意:毛玻璃效果api是ios8的,適配ios8以下的請用其他方法
-(void)setnavigationsubview{
 
 // 毛玻璃背景
 uiimageview *bgimgview = [[uiimageview alloc] initwithframe:_navigationview.bounds];
 bgimgview.image = [uiimage imagenamed:@"666"];
 [_navigationview addsubview:bgimgview];
 
 /** 毛玻璃特效類型
  * uiblureffectstyleextralight,
  * uiblureffectstylelight,
  * uiblureffectstyledark
  */
 uiblureffect * blureffect = [uiblureffect effectwithstyle:uiblureffectstyledark];
 // 毛玻璃視圖
 uivisualeffectview * effectview = [[uivisualeffectview alloc] initwitheffect:blureffect];
 //添加到要有毛玻璃特效的控件中
 effectview.frame = bgimgview.bounds;
 [bgimgview addsubview:effectview];
 //設置模糊透明度
 effectview.alpha = 0.9f;
 
 //中間文本框
 uiview *centertextview = [[uiview alloc]init];
 self.centertextview = centertextview;
 cgfloat centertextviewx = 0;
 cgfloat centertextviewy = 64;
 cgfloat centertextvieww = 0;
 cgfloat centertextviewh = 0;
 
 //文字大小
 nsstring *title = @"pg.lostk開啟后搖滾的新圖景";
 nsstring *desc = @"搖滾清心坊8套";
 cgsize titlesize = [title sizewithattributes:@{nsfontattributename:[uifont systemfontofsize:12]}];
 cgsize descsize = [desc sizewithattributes:@{nsfontattributename:[uifont systemfontofsize:11]}];
 centertextvieww = titlesize.width > descsize.width ? titlesize.width : descsize.width;
 centertextviewh = titlesize.height + descsize.height +10;
 centertextviewx = (screenwidth - centertextvieww) / 2;
 centertextview.frame = cgrectmake(centertextviewx, centertextviewy, centertextvieww, centertextviewh);
 
 //文字label
 uilabel *titlelabel = [[uilabel alloc]init];
 titlelabel.text = title;
 titlelabel.font = [uifont systemfontofsize:12];
 titlelabel.textcolor = [uicolor whitecolor];
 titlelabel.frame = cgrectmake(0,5, centertextvieww, titlesize.height);
 
 uilabel *desclabel = [[uilabel alloc]init];
 desclabel.textalignment = nstextalignmentcenter;
 desclabel.text = desc;
 desclabel.font = [uifont systemfontofsize:11];
 desclabel.textcolor = [uicolor whitecolor];
 desclabel.frame = cgrectmake(0, titlesize.height + 5, centertextvieww, descsize.height);
 
 [centertextview addsubview:titlelabel];
 [centertextview addsubview:desclabel];
 [_navigationview addsubview:centertextview];
}
聲明控件
 
@property(nonatomic,strong) uiview *navigationview;  // 導航欄
@property(nonatomic,strong) uiview *centertextview;  // title文字
@property (assign, nonatomic) cgfloat lastoffsety;  // 記錄上一次位置
@property (nonatomic,strong) uiimageview *scaleimageview; // 頂部圖片
核心代碼
 
#pragma mark - scrollviewdelegate
- (void)scrollviewdidscroll:(uiscrollview *)scrollview {
 
 // 計算當前偏移位置
 cgfloat offsety = scrollview.contentoffset.y;
 cgfloat delta = offsety - _lastoffsety;
 dlog(@"delta=%f",delta);
 dlog(@"offsety=%f",offsety);
 cgfloat height = kheardh - delta;
 if (height < knavbarh) {
  height = knavbarh;
 }
 cgfloat margin = 205;
 if (delta>margin && delta<margin+39) {
  self.centertextview.y = 64 - (delta-margin);
  self.centertextview.alpha = 1.0;
 }
 
 if (delta>margin+39) {
  self.centertextview.y = 25;
  self.centertextview.alpha = 1.0;
 }
 if (delta<=margin) {
  self.centertextview.alpha = 0;
 }
 if (delta<= 0) {
  self.centertextview.y =64;
  self.centertextview.alpha = 0.0;
 }
 [_scaleimageview mas_updateconstraints:^(masconstraintmaker *make) {
  make.height.mas_equalto(height);
 }];
 
 cgfloat alpha = delta / (kheardh - knavbarh);
 if (alpha >= 1.0) {
  alpha = 1.0;
 }
 self.navigationview.alpha = alpha;
}

總結

以上就是這篇文章的全部內容,希望對大家的學習或者工作帶來一定的幫助,如果有疑問大家可以留言交流。

延伸 · 閱讀

精彩推薦
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下...

    jiangamh8882021-01-11
  • IOSiOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)

    iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和

    這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關資料,需要的朋友可以參考下...

    CodingFire13652021-02-26
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

    iOS實現控制屏幕常亮不變暗的方法示例

    最近在工作中遇到了要將iOS屏幕保持常亮的需求,所以下面這篇文章主要給大家介紹了關于利用iOS如何實現控制屏幕常亮不變暗的方法,文中給出了詳細的...

    隨風13332021-04-02
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

    在iOS開發中視圖的切換是很頻繁的,獨立的視圖應用在實際開發過程中并不常見,除非你的應用足夠簡單。在iOS開發中常用的視圖切換有三種,今天我們將...

    執著丶執念5282021-01-16
  • IOSiOS中MD5加密算法的介紹和使用

    iOS中MD5加密算法的介紹和使用

    MD5加密是最常用的加密方法之一,是從一段字符串中通過相應特征生成一段32位的數字字母混合碼。對輸入信息生成唯一的128位散列值(32個字符)。這篇文...

    LYSNote5432021-02-04
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

    iOS開發技巧之狀態欄字體顏色的設置方法

    有時候我們需要根據不同的背景修改狀態欄字體的顏色,下面這篇文章主要給大家介紹了關于iOS開發技巧之狀態欄字體顏色的設置方法,文中通過示例代碼...

    夢想家-mxj8922021-05-10
  • IOS詳解iOS中多個網絡請求的同步問題總結

    詳解iOS中多個網絡請求的同步問題總結

    這篇文章主要介紹了詳解iOS中多個網絡請求的同步問題總結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    liang199111312021-03-15
  • IOSiOS中UILabel實現長按復制功能實例代碼

    iOS中UILabel實現長按復制功能實例代碼

    在iOS開發過程中,有時候會用到UILabel展示的內容,那么就設計到點擊UILabel復制它上面展示的內容的功能,也就是Label長按復制功能,下面這篇文章主要給大...

    devilx12792021-04-02
主站蜘蛛池模板: 亚洲国产成人精品无码区APP | 亚洲欧美日韩另类在线 | 精品无码国产污污污免费网站2 | 俺去俺来也在线www色官网 | 99精品久久精品一区二区 | 国产黄频在线观看 | 亚洲国产免费观看视频 | 三级伦理影院 | 人人人人看人人人做人人 | 亚洲AV人无码综合在线观看蜜桃 | 波多野结衣178部中文字幕 | 狠狠做五月深爱婷婷天天综合 | 色播影院性播影院私人影院 | 236宅宅2021最新理论 | 亚拍一区| 91综合精品网站久久 | 视频在线观看高清免费看 | 色婷婷婷丁香亚洲综合不卡 | 西野翔全部作品在线观看 | 思思99热久久精品在2019线 | 成人性色生活片免费网 | 国产欧美日韩综合二区三区 | 无颜之月5集全免费看无删除 | 精品国产欧美精品v | 久久精品中文字幕 | 午夜久久精品 | 高清免费毛片 | 我和黑色丝袜班主任 | 色综合久久天天综合观看 | 涩涩成人 | freesex性欧美炮机喷潮 | 午夜免费小视频 | 强插美女| 久久国产精品无码视欧美 | 精品福利视频一区二区三区 | 国产成人综合一区精品 | aaa大片| 黄www片 | 国产成人8x视频一区二区 | 99久久精品国内 | 女人叉开腿让男人捅 |