iOS仿AirPods彈出動(dòng)畫(huà)
本文實(shí)例為大家分享了iOS仿AirPods彈出動(dòng)畫(huà)的具體代碼,供大家參考,具體內(nèi)容如下
效果圖
預(yù)覽圖
思路
在當(dāng)前ViewController下Present另外一個(gè)AnimationViewController,在彈出的AnimationViewController中播放動(dòng)畫(huà),彈出的時(shí)候原來(lái)的ViewController上有一個(gè)全屏覆蓋的maskView,在彈出時(shí),有一個(gè)漸變動(dòng)畫(huà)(頁(yè)面漸黑),在AnimationViewController聲明一個(gè)代理,在代理方法中實(shí)現(xiàn)收起的動(dòng)畫(huà)效果(dissmissController和maskView消失)
主要代碼
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有一個(gè)枚舉值,在iOS13以前modalPresentationStyle的默認(rèn)值為UIModalPresentationFullScreen,iOS13以后變成了UIModalPresentationPageSheet,在這里我們把style設(shè)置為UIModalPresentationOverCurrentContext彈出的這個(gè)控制器就會(huì)覆蓋在原來(lái)的控制器之上
- (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;
}
一個(gè)覆蓋全屏的maskView采用懶加載的方式實(shí)現(xiàn)
- (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];
}
動(dòng)畫(huà)這里用到的是Lottie這個(gè)動(dòng)畫(huà)開(kāi)源庫(kù)(Airbnb),這個(gè)開(kāi)源庫(kù)主要的功能是可以將After Effects制作的動(dòng)畫(huà)通過(guò)插件導(dǎo)出為json格式的文件,然后通過(guò)這個(gè)開(kāi)源庫(kù)解析成動(dòng)畫(huà)。
- (void)onConfirmButtonClick
{
if ([self.delegate respondsToSelector:@selector(onAirPodsAnimationViewControllerConfirmButtonClick:)]) {
[self dismissViewControllerAnimated:YES completion:nil];
[self.delegate onAirPodsAnimationViewControllerConfirmButtonClick:self];
}
}
dissmiss當(dāng)前的控制器,讓viewController來(lái)實(shí)現(xiàn)這個(gè)代理方法,并且在代理方法中隱藏maskView
- (void)onAirPodsAnimationViewControllerConfirmButtonClick:(HCAirPodsAnimationViewController *)vc
{
[UIView animateWithDuration:0.2 animations:^{
self.maskBgView.alpha = 0.0;
} completion:nil];
}
項(xiàng)目地址:AirPodsAnimation
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:iOS常見(jiàn)算法以及應(yīng)用知識(shí)點(diǎn)總結(jié)
欄 目:IOS
本文標(biāo)題:iOS仿AirPods彈出動(dòng)畫(huà)
本文地址:http://www.jygsgssxh.com/a1/IOS/11859.html
您可能感興趣的文章
- 01-11iOS常用算法之兩個(gè)有序數(shù)組合并(要求時(shí)間復(fù)雜度為0(n))
- 01-11iOS 彈幕功能的實(shí)現(xiàn)思路圖解
- 01-11iOS調(diào)試Block引用對(duì)象無(wú)法被釋放的小技巧分享
- 01-11iOS動(dòng)態(tài)更換Icon的全過(guò)程記錄
- 01-11iOS實(shí)現(xiàn)文本分頁(yè)的方法示例
- 01-11iOS常見(jiàn)宏理解及使用方法
- 01-11iOs遷至WKWebView跨過(guò)的一些坑
- 01-11iOS模擬中獎(jiǎng)名單循環(huán)滾動(dòng)效果
- 01-11Python一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資源
- 01-11iOS中如何獲取某個(gè)視圖的截圖詳析


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-11UILabel顯示定時(shí)器文本跳動(dòng)問(wèn)題的解決
- 01-11iOS常用算法之兩個(gè)有序數(shù)組合并(要
- 01-11iOS 彈幕功能的實(shí)現(xiàn)思路圖解
- 01-11詳解MacOs免密登錄CentOs操作步驟
- 01-11iOS動(dòng)態(tài)更換Icon的全過(guò)程記錄
- 01-11iOS調(diào)試Block引用對(duì)象無(wú)法被釋放的小技
- 01-11iOS常見(jiàn)宏理解及使用方法
- 01-11iOS實(shí)現(xiàn)文本分頁(yè)的方法示例
- 01-11iOs遷至WKWebView跨過(guò)的一些坑
- 01-11iOS模擬中獎(jiǎng)名單循環(huán)滾動(dòng)效果
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置


