小技巧:動(dòng)畫

動(dòng)畫效果方法
animateWithDuration:time(時(shí)間)animation:^{

}

加特效

    [UIView animateWithDuration:1 delay:0.5 usingSpringWithDamping:0.5 initialSpringVelocity:15 options:UIViewAnimationOptionCurveEaseOut animations:^{

    } completion:nil];

切換VC時(shí)翻頁效果

    // 創(chuàng)建UINavigationController
    UINavigationController *vc = [[UINavigationController alloc]initWithRootViewController:[[CYXTabBarController alloc]init]];
    
    // 切換窗口的根控制器進(jìn)行跳轉(zhuǎn)
    [UIApplication sharedApplication].keyWindow.rootViewController = vc;
    
    CATransition *anim = [CATransition animation];
    anim.type = @"pageCurl";
    anim.duration = 1;
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];

圖標(biāo)抖動(dòng)

- (IBAction)beginButn:(id)sender {

    //創(chuàng)建動(dòng)畫
    CAKeyframeAnimation * keyAnimaion = [CAKeyframeAnimation animation];
    keyAnimaion.keyPath = @"transform.rotation";
    keyAnimaion.values = @[@(-10 / 180.0 * M_PI),@(10 /180.0 * M_PI),@(-10/ 180.0 * M_PI)];//度數(shù)轉(zhuǎn)弧度

    keyAnimaion.removedOnCompletion = NO;
    keyAnimaion.fillMode = kCAFillModeForwards;
    keyAnimaion.duration = 0.3;
    keyAnimaion.repeatCount = MAXFLOAT;
    [self.iconImageView.layer addAnimation:keyAnimaion forKey:nil];

}

改變frame

-(void)changeFrame{

    CGRect originalRect = self.anView.frame;
    CGRect rect = CGRectMake(self.anView.frame.origin.x-20, self.anView.frame.origin.y-120, 160, 80);

    [UIView animateWithDuration:1 animations:^{
        self.anView.frame = rect;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            self.anView.frame = originalRect;
        }];

    }];
}

拉伸動(dòng)畫

-(void)changeBounds{

    CGRect originalBounds = self.anView.bounds;
    //盡管這個(gè)rect的x,y跟原始的不同,動(dòng)畫也只是改變了寬高
    CGRect rect = CGRectMake(0, 0, 300, 120);

    [UIView animateWithDuration:1 animations:^{
    self.anView.bounds = rect;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            self.anView.bounds = originalBounds;
        }];

    }];
}

位移動(dòng)畫

-(void)changeCenter{

    CGPoint originalPoint = self.anView.center;
    CGPoint point = CGPointMake(self.anView.center.x, self.anView.center.y-170);

    [UIView animateWithDuration:0.3 animations:^{
        self.anView.center = point;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            self.anView.center = originalPoint;
        }];

    }]; 
}

旋轉(zhuǎn)動(dòng)畫

-(void)transform{
    CGAffineTransform originalTransform = self.anView.transform;
    [UIView animateWithDuration:2 animations:^{
        //self.anView.transform = CGAffineTransformMakeScale(0.6, 0.6);//縮放
        //self.anView.transform = CGAffineTransformMakeTranslation(60, -60);
        self.anView.transform = CGAffineTransformMakeRotation(4.0f);

    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2 animations:^{
            self.anView.transform = originalTransform;

        }];
    }];
}

翻轉(zhuǎn)動(dòng)畫

-(void)transitionAnimation{
    [UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        //self.anView.backgroundColor = [UIColor blueColor];
    } completion:^(BOOL finished) {
        [UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        //self.anView.backgroundColor = [UIColor greenColor];
        } completion:^(BOOL finished) {

        }];
    }];
}

透明度動(dòng)畫

-(void)alpha{
    [UIView animateWithDuration:2 animations:^{
        self.anView.alpha = 0.3;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2 animations:^{
            self.anView.alpha = 1;
        }];

    }];
}

背景變化

-(void)changeBackground{

    [UIView animateKeyframesWithDuration:9.0 delay:0.f options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
        [UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:1.0 / 4 animations:^{
            self.anView.backgroundColor = [UIColor colorWithRed:0.9475 green:0.1921 blue:0.1746 alpha:1.0];
        }];
        [UIView addKeyframeWithRelativeStartTime:1.0 / 4 relativeDuration:1.0 / 4 animations:^{
            self.anView.backgroundColor = [UIColor colorWithRed:0.1064 green:0.6052 blue:0.0334 alpha:1.0];
        }];
        [UIView addKeyframeWithRelativeStartTime:2.0 / 4 relativeDuration:1.0 / 4 animations:^{
            self.anView.backgroundColor = [UIColor colorWithRed:0.1366 green:0.3017 blue:0.8411 alpha:1.0];
        }];
        [UIView addKeyframeWithRelativeStartTime:3.0 / 4 relativeDuration:1.0 / 4 animations:^{
            self.anView.backgroundColor = [UIColor colorWithRed:0.619 green:0.037 blue:0.6719 alpha:1.0];
        }];
        [UIView addKeyframeWithRelativeStartTime:3.0 / 4 relativeDuration:1.0 / 4 animations:^{
            self.anView.backgroundColor = [UIColor whiteColor];
        }];
    } completion:^(BOOL finished) {
        NSLog(@"動(dòng)畫結(jié)束");
    }];
}

自作旋轉(zhuǎn)動(dòng)畫

// 設(shè)置動(dòng)畫的延遲及類型
        NSTimeInterval animationDuration = 1;
        CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        // 注意value類型為id類型
        animation.fromValue = (id) 0;
        animation.toValue = @(M_PI*2);
        animation.duration = animationDuration;
        animation.timingFunction = linearCurve;
        // 這個(gè)參數(shù)不要忘了,是在昨晚動(dòng)畫之后保持動(dòng)畫完成的狀態(tài)
        animation.removedOnCompletion = NO;
        animation.repeatCount = INFINITY;
        animation.fillMode = kCAFillModeForwards;
        animation.autoreverses = NO;
        // 將動(dòng)畫加到mask上
        [_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"];

// 添加到動(dòng)畫組
// 創(chuàng)建動(dòng)畫組,并設(shè)置相關(guān)屬性
        CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
        animationGroup.duration = animationDuration;
        animationGroup.repeatCount = INFINITY;
        animationGroup.removedOnCompletion = NO;
        animationGroup.timingFunction = linearCurve;

        // strokeStart動(dòng)畫
        CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        strokeStartAnimation.fromValue = @0.015;
        strokeStartAnimation.toValue = @0.515;

        // strokeEnd動(dòng)畫
        CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        strokeEndAnimation.fromValue = @0.485;
        strokeEndAnimation.toValue = @0.985;

        // 將動(dòng)畫加到動(dòng)畫組
        animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation];
        [_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"];


VC跳轉(zhuǎn)動(dòng)畫

// modal方式
    TestViewController *vc = [[TestViewController alloc] init];
    vc.view.backgroundColor = [UIColor redColor];
    vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:vc animated:YES completion:nil];

// push方式
    TestViewController *vc = [[TestViewController alloc] init];
    vc.view.backgroundColor = [UIColor redColor];
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:0.80];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
    [self.navigationController pushViewController:vc animated:YES];
    [UIView commitAnimations];

http://www.itdecent.cn/p/77847c0027c9
http://www.itdecent.cn/p/92532c2b1d55

有用資料

https://github.com/airbnb/lottie-ios *

http://www.itdecent.cn/c/080cc1641d93

http://www.itdecent.cn/p/7384c0c930df

http://www.itdecent.cn/p/ede91913caab

http://www.cnblogs.com/fengmin/p/6206282.html

https://github.com/ameizi/awesome-ios-animation

http://www.itdecent.cn/p/cfde1c24248b

http://www.itdecent.cn/p/a138a8832452

http://www.itdecent.cn/p/406a14e5d9a5

http://www.itdecent.cn/p/b660eb8b8bc1

https://github.com/xiaochaofeiyu/YSCAnimation *有趣

貝塞爾曲線
http://www.itdecent.cn/p/c883fbf52681

螞蟻森林
http://www.itdecent.cn/p/540a7e6f7b40

tableview動(dòng)畫
http://www.itdecent.cn/p/65b251c62f71

轉(zhuǎn)場(chǎng)動(dòng)畫
http://www.itdecent.cn/p/802d47f0f311

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

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,039評(píng)論 25 709
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,873評(píng)論 2 45
  • XML配置 測(cè)試代碼 經(jīng)過動(dòng)手實(shí)驗(yàn),證明Spring合并對(duì)于List類型,并無覆蓋。接下來,我們看看其源碼實(shí)現(xiàn) M...
    google666s閱讀 714評(píng)論 0 50
  • 今天給孩子買了手套,大力和小寶。給小貓貓買了雙鞋,腳都起凍瘡了,真是受罪。 在歐尚給自己買了個(gè)小斜肩包,主要價(jià)...
    芳老頭閱讀 151評(píng)論 0 0
  • 人生是一串由無數(shù)小煩惱組成的念珠,達(dá)觀的人是笑著數(shù)完這串念珠的。(大仲馬)
    strong118閱讀 190評(píng)論 0 1

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