国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS仿AirPods彈出動畫

2020-07-26 02:18:39
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS仿AirPods彈出動畫的具體代碼,供大家參考,具體內容如下

效果圖

預覽圖

思路

在當前ViewController下Present另外一個AnimationViewController,在彈出的AnimationViewController中播放動畫,彈出的時候原來的ViewController上有一個全屏覆蓋的maskView,在彈出時,有一個漸變動畫(頁面漸黑),在AnimationViewController聲明一個代理,在代理方法中實現收起的動畫效果(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];  }];

模態跳轉的style有一個枚舉值,在iOS13以前modalPresentationStyle的默認值為UIModalPresentationFullScreen,iOS13以后變成了UIModalPresentationPageSheet,在這里我們把style設置為UIModalPresentationOverCurrentContext彈出的這個控制器就會覆蓋在原來的控制器之上

- (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采用懶加載的方式實現

- (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制作的動畫通過插件導出為json格式的文件,然后通過這個開源庫解析成動畫。

- (void)onConfirmButtonClick{  if ([self.delegate respondsToSelector:@selector(onAirPodsAnimationViewControllerConfirmButtonClick:)]) {    [self dismissViewControllerAnimated:YES completion:nil];    [self.delegate onAirPodsAnimationViewControllerConfirmButtonClick:self];  }}

dissmiss當前的控制器,讓viewController來實現這個代理方法,并且在代理方法中隱藏maskView

- (void)onAirPodsAnimationViewControllerConfirmButtonClick:(HCAirPodsAnimationViewController *)vc{  [UIView animateWithDuration:0.2 animations:^{    self.maskBgView.alpha = 0.0;  } completion:nil];}

項目地址:AirPodsAnimation

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡阳市| 耿马| 信宜市| 同仁县| 大同市| 双峰县| 会昌县| 信丰县| 唐海县| 南澳县| 洞头县| 柘城县| 嘉义市| 武川县| 松原市| 荆门市| 德兴市| 汕尾市| 内乡县| 孟津县| 鄂托克旗| 高雄县| 浦北县| 万全县| 磐安县| 泸西县| 德庆县| 黄浦区| 郑州市| 井研县| 镇安县| 苗栗县| 澜沧| 津市市| 汾阳市| 临泽县| 鄂州市| 合山市| 天镇县| 肃北| 酉阳|