#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@property (weak, nonatomic) IBOutlet UIImageView *headerImageV;
@property (weak, nonatomic) IBOutlet UIImageView *footImageView;
@property (weak, nonatomic) IBOutlet UIImageView *buleImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//动画
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
/* //UIView动画
//1.不带结束block的动画
// [UIView animateWithDuration:2 animations:^{
// _redView.frame = CGRectMake(10, 500, 133, 96);
// }];
//2.带结束block的动画
//渐变效果
[UIView animateWithDuration:2 animations:^{
_redView.frame = CGRectMake(10, 500, 133, 96);
_redView.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2 animations:^{
//在带结束block里面嵌套一个不带结束block的动画
_redView.frame = CGRectMake(12, 15, 133, 96);
_redView.alpha = 1;
}];
}];
*/
//阻尼
//弹簧效果 initialSpringVelocity:似乎是力度,不太清楚这个
// [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.05 initialSpringVelocity:100000 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
// _redView.frame = CGRectMake(12, 15, 133, 97);
// } completion:^(BOOL finished) {
//
// }];
/*
//UIView帧动画(可以做一个移动的动画)
[UIView animateKeyframesWithDuration:6 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1/3.0 animations:^{
_redView.frame = CGRectMake(100, 100, 100, 100);
}];
[UIView addKeyframeWithRelativeStartTime:1/3.0 relativeDuration:1/3.0 animations:^{
_redView.frame = CGRectMake(100, 400, 100, 100);
}];
[UIView addKeyframeWithRelativeStartTime:2/3.0 relativeDuration:1/3.0 animations:^{
_redView.frame = CGRectMake(200, 30, 100, 100);
}];
} completion:^(BOOL finished) {
}];
*/
/*
//UIView的原始写法
[UIView beginAnimations:@"原始动画" context:nil];
//动画持续时间
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:5];//重复次数
_redView.frame = CGRectMake(12, 200, 133, 96);
//要签协议
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationStop)];
[UIView commitAnimations];//提交动画
*/
/*
//layer动画 要有协议
CATransition *animation1 = [CATransition animation];
//设置时间
animation1.duration = 2;
//设置次数
animation1.repeatCount = 2;//(无限重复)
//设置动画样式
// animation1.type = @"rippleEffect";//波纹效果
// animation.type = @"cube"; //旋转
// animation.type = @"suckEffect";
// animation.type = @"oglFlip";
animation1.type = @"rippleEffect";//波纹
// animation.type = @"pageCurl";//页撕开
// animation.type = @"pageUnCurl";//页粘贴
// animation.type = @"cameraIrisHollowOpen";//摄像机打开
// animation.type = @"cameraIrisHollowClose";//摄像机关闭
//字样式
animation1.subtype = kCATransitionFromRight;
//获取动画结束 为了确定停止
[animation1 setDelegate:self];
[animation1 setValue:@"美女波动" forKey:@"bodong"];
//添加动画
[_imageV.layer addAnimation:animation1 forKey:nil];
*/
/*
//旋转动画(平面的)
//Basic:基础 rotaion:旋转
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
basicAnimation.duration = 2;
basicAnimation.repeatCount = MAXFLOAT;
basicAnimation.fromValue = [NSNumber numberWithInt:1];
basicAnimation.toValue = [NSNumber numberWithInt:M_PI*10];
[_headerImageV.layer addAnimation:basicAnimation forKey:@"rotation"];
// [_footImageView.layer addAnimation:basicAnimation forKey:@"rotaion"];
//缩放效果(动心效果)
CABasicAnimation *basesicAnimation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
basesicAnimation1.duration = 0.01;
basesicAnimation1.repeatCount = MAXFLOAT;
basesicAnimation1.fromValue = [NSNumber numberWithFloat:0.5];
//放大的倍数
basesicAnimation1.toValue = [NSNumber numberWithFloat:2];
[_imageV.layer addAnimation:basesicAnimation1 forKey:@"scale"];
[_imageV.layer addAnimation:basicAnimation forKey:@"rotation"];
*/
//transform
[UIView animateWithDuration:2 animations:^{
//make 移动一次
// _buleImageView.transform = CGAffineTransformMakeTranslation(100, 100);
// //不带make连续移动
// _buleImageView.transform = CGAffineTransformTranslate(_buleImageView.transform, 100, 100);
// _buleImageView.transform = CGAffineTransformRotate(_buleImageView.transform, M_PI_4);
// //带make的旋转:只执行一次
// _buleImageView.transform = CGAffineTransformMakeRotation(M_PI_4);
//缩放(带make)
// _buleImageView.transform = CGAffineTransformScale(_buleImageView.transform, 2, 0.5);
//3D效果的旋转
// _buleImageView.layer.transform = CATransform3DRotate(_buleImageView.layer.transform, M_PI_4, 0, 1, 0);
//关键帧动画 position:位置
CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, _buleImageView.center.x, _buleImageView.center.y);
//依次添加每个点,让其移动
CGPathAddLineToPoint(path, NULL, 100, 100);
CGPathAddLineToPoint(path, NULL, 100, 200);
CGPathAddLineToPoint(path, NULL, 200, 100);
CGPathAddLineToPoint(path, NULL, 300, 400);
//添加路径
[keyframeAnimation setPath:path];
//设置时间
[keyframeAnimation setDuration:10];
//设置次数 重复次数
[keyframeAnimation setRepeatCount:10];
[_buleImageView.layer addAnimation:keyframeAnimation forKey:@"position"];
}];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSString *str = [anim valueForKey:@"bodong"];
if ([str isEqualToString:@"美女波动"]) {
NSLog(@"结束");
}
}
-(void)animationStop
{
NSLog(@"动画结束");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
动画
最新推荐文章于 2023-06-25 20:51:27 发布
