资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOS中怎么实现一个AirPods弹出动画-创新互联

本篇文章给大家分享的是有关iOS中怎么实现一个AirPods弹出动画,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

目前累计服务客户上1000家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站制作、网站设计、外贸网站建设、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。

思路

在当前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];
}

以上就是iOS中怎么实现一个AirPods弹出动画,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联网站建设公司行业资讯频道。

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:iOS中怎么实现一个AirPods弹出动画-创新互联
网页网址:http://cdkjz.cn/article/iiedc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220