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

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

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

服務(wù)器之家 - 編程語言 - IOS - iOS仿AirPods彈出動畫

iOS仿AirPods彈出動畫

2021-05-28 16:02Peter_Huang0623 IOS

這篇文章主要為大家詳細介紹了iOS仿AirPods彈出動畫的實現(xiàn),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了ios仿airpods彈出動畫的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

iOS仿AirPods彈出動畫

預(yù)覽圖

思路

在當前viewcontroller下present另外一個animationviewcontroller,在彈出的animationviewcontroller中播放動畫,彈出的時候原來的viewcontroller上有一個全屏覆蓋的maskview,在彈出時,有一個漸變動畫(頁面漸黑),在animationviewcontroller聲明一個代理,在代理方法中實現(xiàn)收起的動畫效果(dissmisscontroller和maskview消失)

主要代碼

?
1
2
3
4
5
6
7
8
9
10
11
hcairpodsanimationviewcontroller *vc = [[hcairpodsanimationviewcontroller alloc] init];
  vc.delegate = self;
  vc.modalpresentationstyle = uimodalpresentationovercurrentcontext;
  
  [uiview animatewithduration:0.2 animations:^{
    self.maskbgview.alpha = 0.5;
  } completion:nil];
  
  [self presentviewcontroller:vc animated:yes completion:^{
    [vc.animationview play];
  }];

模態(tài)跳轉(zhuǎn)的style有一個枚舉值,在ios13以前modalpresentationstyle的默認值為uimodalpresentationfullscreen,ios13以后變成了uimodalpresentationpagesheet,在這里我們把style設(shè)置為uimodalpresentationovercurrentcontext彈出的這個控制器就會覆蓋在原來的控制器之上

?
1
2
3
4
5
6
7
8
9
10
- (uiview *)maskbgview
{
  if (!_maskbgview) {
    _maskbgview = [[uiview alloc] initwithframe:cgrectmake(0, 0, [uiscreen mainscreen].bounds.size.width, [uiscreen mainscreen].bounds.size.height)];
    _maskbgview.backgroundcolor = [uicolor blackcolor];
    _maskbgview.alpha = 0;
    [self.view addsubview:_maskbgview];
  }
  return _maskbgview;
}

一個覆蓋全屏的maskview采用懶加載的方式實現(xiàn)

?
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
- (void)initcontentview
{
  cgfloat containerw = screen_width - 20;
  cgfloat containerh = containerw * 0.9;
  uiview *containerview = [[uiview alloc] initwithframe:cgrectmake(10, screen_height - containerh - 10, containerw, containerh)];
  containerview.layer.cornerradius = 20;
  containerview.backgroundcolor = [uicolor whitecolor];
  [self.view addsubview:containerview];
  
  self.animationview = [[lotanimationview alloc] initwithframe:cgrectmake(70, 70, containerw - 140, containerh - 140)];
  [containerview addsubview:self.animationview];
  self.animationview.animation = @"gift_animation";
  
  self.animationview.loopanimation = yes;
  
  uibutton *confirmbutton = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 200, 34)];
  confirmbutton.center = cgpointmake(self.animationview.center.x, containerh - 44);
  
  [confirmbutton settitle:@"close" forstate:uicontrolstatenormal];
  [confirmbutton settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal];
  
  [confirmbutton setbackgroundcolor:[uicolor bluecolor]];
  confirmbutton.layer.cornerradius = 10;
  
  [confirmbutton addtarget:self action:@selector(onconfirmbuttonclick) forcontrolevents:uicontroleventtouchupinside];
  [containerview addsubview:confirmbutton];
}

動畫這里用到的是lottie這個動畫開源庫(airbnb),這個開源庫主要的功能是可以將after effects制作的動畫通過插件導(dǎo)出為json格式的文件,然后通過這個開源庫解析成動畫。

?
1
2
3
4
5
6
7
- (void)onconfirmbuttonclick
{
  if ([self.delegate respondstoselector:@selector(onairpodsanimationviewcontrollerconfirmbuttonclick:)]) {
    [self dismissviewcontrolleranimated:yes completion:nil];
    [self.delegate onairpodsanimationviewcontrollerconfirmbuttonclick:self];
  }
}

dissmiss當前的控制器,讓viewcontroller來實現(xiàn)這個代理方法,并且在代理方法中隱藏maskview

?
1
2
3
4
5
6
- (void)onairpodsanimationviewcontrollerconfirmbuttonclick:(hcairpodsanimationviewcontroller *)vc
{
  [uiview animatewithduration:0.2 animations:^{
    self.maskbgview.alpha = 0.0;
  } completion:nil];
}

項目地址:airpodsanimation

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/Peter_Huang0623/article/details/103533619

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久亚洲免费视频 | 久久免费看少妇级毛片蜜臀 | 日本一区二区三区视频在线观看 | 亚洲第一页综合 | 毛片a级放荡的护士hd | 精品国产麻豆AV无码 | 女女同性做爰xxoo亲吻 | 母乳在线| 二次元美女脱裤子让男人桶爽 | 国产男女爱视频在线观看 | 精品区卡一卡2卡三免费 | 99在线视频精品 | 给我一个黄色网址 | 近亲乱中文字幕 | 亚洲老头老太hd | 被强迫变性翘秘书 | 白丝爆动漫羞羞动漫软件 | 村上里沙40分钟在线观看 | 天天操天天做 | 国内精品九一在线播放 | 男女视频在线观看网站 | 性夜夜春夜夜爽AA片A | 免费的强动漫人物的 | 高h折磨调教古代 | 四虎网站在线 | 男女拍拍拍免费视频网站 | 国产欧美日韩专区毛茸茸 | 国产精品久久久久这里只有精品 | 青青草影院在线观看 | 99久久无色码中文字幕 | 亚洲成a人不卡在线观看 | 亚洲AV无码一区二区三区乱子伦 | 午夜AV亚洲一码二中文字幕青青 | 高清黄色直接看 | 鄂州一家三口完整版免费 | 91成| 欧美性野久久久久久久久 | 好妈妈7在线观看高清 | 91在线免费看 | 天堂va在线 | 国产伦码精品一区二区三区 |