iOS-嗶哩嗶哩動畫_開機動畫

最近因為需要,做了下嗶哩嗶哩動畫這個應(yīng)用。從數(shù)據(jù)、素材的抓取、分類、測試,到應(yīng)用的基本功能實現(xiàn),確實用了一段時間。下面是做嗶哩嗶哩動畫的開機動畫效果的實現(xiàn)。

![Uploading LuanchImage設(shè)置_552569.png . . .]](http://upload-images.jianshu.io/upload_images/2023147-b27b7518b9e7f8c7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

動畫開機圖.png

從圖一到圖二,中間的人物從小到大,從透明到呈現(xiàn)的過程。
實現(xiàn)這個效果并不難,步驟如下
1.在LuanchImage設(shè)置開機圖片

LuanchImage設(shè)置.png
LuanchImage.png

2.使用CABasicAnimationGroup實現(xiàn)動畫效果
這里創(chuàng)建了一個視圖控制器類LaunchViewController,用于實現(xiàn)動畫效果。
設(shè)置兩個屬性,其中bgImageView是背景圖,playImageView是做動畫的圖片。

@property (nonatomic,strong)UIImageView  *bgImageView;
@property (nonatomic,strong)UIImageView  *playImageView;

給這兩個屬性懶加載

- (UIImageView *)bgImageView{
   
   if(!_bgImageView){
       _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
       _bgImageView.image = [UIImage imageNamed:@"bilibili_splash_iphone_bg"];
   }
   return _bgImageView;
}

- (UIImageView *)playImageView{
   
   if(!_playImageView){
       _playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2, ScreenHeight/2-100, 1, 1.3)];
       _playImageView.image = [UIImage imageNamed:@"bilibili_splash_default"];
   }
   return _playImageView;
}

viewDidLoad中把視圖添加上去

    [self.view addSubview:self.bgImageView];
    [self.bgImageView addSubview:self.playImageView];
    [self performSelector:@selector(animationLunch) withObject:self afterDelay:0];

animationLunch中實現(xiàn)組合動畫效果

- (void)animationLunch{
    
    CGFloat duration = 1.5;
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scale.fromValue = @1;
    scale.toValue = @(ScreenWidth - 40);
    scale.duration = duration;
    scale.repeatCount = 1;
    scale.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    
    CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacity.fromValue = @0;
    opacity.toValue = @1;
    opacity.duration = duration;
    scale.repeatCount = 1;
    
    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.animations = @[scale,opacity];
    animationGroup.duration = duration;
    animationGroup.repeatCount = 1;
    //如果是一個動畫CAAnimation,則需要將其removedOnCompletion設(shè)置為NO,要不然fillMode不起作用
    animationGroup.removedOnCompletion = NO;
    //決定當(dāng)前在非active時間段的行為,比如動畫開始之前,動畫結(jié)束之后
    animationGroup.fillMode =kCAFillModeForwards;
    animationGroup.delegate = self;
    [self.playImageView.layer addAnimation:animationGroup forKey:nil];
}

LaunchViewController遵循代理,并實現(xiàn)CAAnimationDelegate協(xié)議

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    [NSThread sleepForTimeInterval:2.0];
    //移除開機動畫
    [self.bgImageView removeFromSuperview];
}

這個類要做的事情完成了,回到AppDelegate中,導(dǎo)入剛創(chuàng)建的類頭文件,在application: didFinishLaunchingWithOptions:中加入以下代碼,把動畫添加到場景中

  _launchVC = [[LaunchViewController alloc] init];
    //添加到場景
    [self.window addSubview:_launchVC.view];
    //放到最頂層
    [self.window bringSubviewToFront:_launchVC.view];
    [self performSelector:@selector(removeLunch) withObject:self afterDelay:2.0];

到此,嗶哩嗶哩動畫的開機動畫效果就實現(xiàn)了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,008評論 25 709
  • 翻譯自“Collection View Programming Guide for iOS” 0 關(guān)于iOS集合視...
    lakerszhy閱讀 4,072評論 1 22
  • 食材 : 面粉100g 酵母1g 做法步驟 : 酵母用溫水和開 倒入面粉中 攪成絮狀,揉成光滑的面團...
    秭歸橙子和水果閱讀 418評論 0 1
  • 哈哈哈,說是“北漂”第一天,但是準(zhǔn)確來說,還沒開始漂起來。 早上,在學(xué)校東苑食堂吃了我最愛的青椒雞肉的餡餅,在心里...
  • 今天出去爬山,回來的很晚,晚上看了一會書,正練字途中累的睡著了,很開心,有種高三的感覺
    文叔哥哥閱讀 164評論 0 1

友情鏈接更多精彩內(nèi)容