亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS仿AirPods彈出動畫

 更新時間:2019年12月14日 13:21:17   作者:Peter_Huang0623  
這篇文章主要為大家詳細介紹了iOS仿AirPods彈出動畫的實現(xiàn),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

效果圖

預(yù)覽圖

思路

在當前ViewController下Present另外一個AnimationViewController,在彈出的AnimationViewController中播放動畫,彈出的時候原來的ViewController上有一個全屏覆蓋的maskView,在彈出時,有一個漸變動畫(頁面漸黑),在AnimationViewController聲明一個代理,在代理方法中實現(xiàn)收起的動畫效果(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有一個枚舉值,在iOS13以前modalPresentationStyle的默認值為UIModalPresentationFullScreen,iOS13以后變成了UIModalPresentationPageSheet,在這里我們把style設(shè)置為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采用懶加載的方式實現(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];
}

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

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

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

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

項目地址:AirPodsAnimation

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

相關(guān)文章

  • iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解

    iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解

    這篇文章主要為大家介紹了iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • 關(guān)于iOS獲取屬性你真的了解嗎?

    關(guān)于iOS獲取屬性你真的了解嗎?

    這篇文章主要給大家介紹了關(guān)于iOS取屬性的相關(guān)資料,當說到取屬性,相信很多的iOS開發(fā)者們會說出很多,但你就真的理解嗎?下面就來詳細,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-12-12
  • iOS通過Runtime實現(xiàn)友盟統(tǒng)計的實例代碼

    iOS通過Runtime實現(xiàn)友盟統(tǒng)計的實例代碼

    本篇文章主要介紹了iOS通過Runtime實現(xiàn)友盟統(tǒng)計的實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • iOS中控制NSLog輸出時機詳解

    iOS中控制NSLog輸出時機詳解

    本文給大家介紹的是iOS開發(fā)中關(guān)于nslog的輸出時機的相關(guān)內(nèi)容,非常簡單實用,有需要的小伙伴可以參考下
    2017-12-12
  • iOS指紋登錄(TouchID)集成方案詳解

    iOS指紋登錄(TouchID)集成方案詳解

    這篇文章主要為大家詳細介紹了iOS指紋登錄TouchID的集成方案,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • iOS利用Block逆向傳值的方式詳解

    iOS利用Block逆向傳值的方式詳解

    大家應(yīng)該都有所了解在iOS開發(fā)中,常見的幾種逆向傳值方式,有代理(delegate)、通知(NSNotification),block等等,之前已經(jīng)給大家介紹了通過代理實現(xiàn)逆向傳值的方法,這篇文章來給大家介紹如何通過Block進行逆向傳值,有需要的朋友們下面跟著小編一起來學(xué)習學(xué)習吧。
    2016-12-12
  • iOS App引導(dǎo)頁開發(fā)教程

    iOS App引導(dǎo)頁開發(fā)教程

    這篇文章主要為大家詳細介紹了iOS App引導(dǎo)頁開發(fā)教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 淺談iOS 數(shù)據(jù)結(jié)構(gòu)之鏈表

    淺談iOS 數(shù)據(jù)結(jié)構(gòu)之鏈表

    這篇文章主要介紹了淺談iOS 數(shù)據(jù)結(jié)構(gòu)之鏈表,本文詳細的介紹了單鏈表和雙鏈表,具有一定的參考價值,有興趣的可以了解一下
    2017-09-09
  • IOS中使用UIWebView 加載網(wǎng)頁、文件、 html的方法

    IOS中使用UIWebView 加載網(wǎng)頁、文件、 html的方法

    UIWebView 是用來加載加載網(wǎng)頁數(shù)據(jù)的一個框,接下來通過本文給大家介紹IOS中使用UIWebView 加載網(wǎng)頁、文件、 html的方法,對本文詳情感興趣的朋友一起學(xué)習吧
    2016-02-02
  • IOS 中動畫的暫停與繼續(xù)播放的詳解

    IOS 中動畫的暫停與繼續(xù)播放的詳解

    這篇文章主要介紹了IOS 中動畫的暫停與繼續(xù)播放的詳解的相關(guān)資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-09-09

最新評論