日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

IOS开发基础之核心动画 基础动画、关键帧、组动画案例

發(fā)布時間:2023/12/18 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发基础之核心动画 基础动画、关键帧、组动画案例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

IOS開發(fā)基礎(chǔ)之核心動畫 基礎(chǔ)動畫、關(guān)鍵幀、組動畫案例

案例源碼在我的主頁里。實現(xiàn)效果圖

// // ViewController.m // 30-核心動畫 // // Created by 魯軍 on 2021/2/21. //#import "ViewController.h" @interface ViewController () @property(nonatomic,weak)CALayer *layer; @end @implementation ViewController - (void)viewDidLoad {[super viewDidLoad];UIView *redView =[[UIView alloc] init];redView.frame =CGRectMake(100, 100, 20, 20);redView.backgroundColor =[UIColor redColor];self.layer=redView.layer ;[self.view addSubview:redView]; }- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{//組動畫CAAnimationGroup *group = [[CAAnimationGroup alloc] init];//創(chuàng)建動畫對象 (做什么動畫)CABasicAnimation *anim = [[CABasicAnimation alloc]init];anim.keyPath = @"transform.rotation";anim.byValue =@(2*M_PI*10);CAKeyframeAnimation *anim1=[[CAKeyframeAnimation alloc] init];anim1.keyPath = @"position";UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];anim1.path = path.CGPath;group.animations=@[anim,anim1];group.duration = 3;group.repeatCount = INT_MAX; // 重復(fù)的次數(shù)//怎么做動畫//添加動畫(對誰做動畫)[self.layer addAnimation:group forKey:nil]; } //關(guān)鍵幀 -(void)test2{//關(guān)鍵幀//創(chuàng)建動畫對象 (做什么動畫)CAKeyframeAnimation *anim = [[CAKeyframeAnimation alloc] init];//怎么做動畫anim.keyPath=@"position";/* NSValue *v1 =[NSValue valueWithCGPoint:CGPointMake(100, 100)];NSValue *v2 =[NSValue valueWithCGPoint:CGPointMake(150, 100)];NSValue *v3 =[NSValue valueWithCGPoint:CGPointMake(100, 150)];NSValue *v4 =[NSValue valueWithCGPoint:CGPointMake(150,150 )];anim.values =@[v1,v2,v3,v4];*/UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];anim.path = path.CGPath;anim.duration = 2;anim.repeatCount = INT_MAX; // 重復(fù)的次數(shù)//添加動畫(對誰做動畫)[self.layer addAnimation:anim forKey:nil]; } //基礎(chǔ)動畫 -(void)testbaseAnimation{//創(chuàng)建動畫對象 (做什么動畫)CABasicAnimation *animation = [[CABasicAnimation alloc] init];//怎么做動畫animation.keyPath = @"position.x";/*animation.fromValue =@(10); 從哪animation.toValue = @(300); 到哪*///每次加10pxanimation.byValue = @(10);//不回去原來的地方animation.fillMode = kCAFillModeForwards;animation.removedOnCompletion=NO;//添加動畫(對誰做動畫)[self.layer addAnimation:animation forKey:nil]; } @end // // LJView.m // 30-核心動畫 // // Created by 魯軍 on 2021/2/21. //#import "LJView.h"@implementation LJView/* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. */ - (void)drawRect:(CGRect)rect {// Drawing codeUIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];[path stroke];}@end

總結(jié)

以上是生活随笔為你收集整理的IOS开发基础之核心动画 基础动画、关键帧、组动画案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。