生活随笔
收集整理的這篇文章主要介紹了
IOS开发基础之核心动画 基础动画、关键帧、组动画案例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IOS開發基礎之核心動畫 基礎動畫、關鍵幀、組動畫案例
案例源碼在我的主頁里。實現效果圖
#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
];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
; [self.layer addAnimation
:group forKey
:nil
];
}
-(void)test2
{CAKeyframeAnimation
*anim
= [[CAKeyframeAnimation alloc
] init
];anim
.keyPath
=@"position";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
; [self.layer addAnimation
:anim forKey
:nil
];
}
-(void)testbaseAnimation
{CABasicAnimation
*animation
= [[CABasicAnimation alloc
] init
];animation
.keyPath
= @"position.x";animation
.byValue
= @(10);animation
.fillMode
= kCAFillModeForwards
;animation
.removedOnCompletion
=NO
;[self.layer addAnimation
:animation forKey
:nil
];
}
@end
#import "LJView.h"@implementation LJView
- (void)drawRect
:(CGRect
)rect
{UIBezierPath
* path
=[UIBezierPath bezierPathWithArcCenter
:CGPointMake(150, 150) radius
:100 startAngle
:0 endAngle
:2*M_PI clockwise
:1];[path stroke
];}@end
總結
以上是生活随笔為你收集整理的IOS开发基础之核心动画 基础动画、关键帧、组动画案例的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。