1 rotationAnimation.removedOnCompletion = NO; 2 3 rotationAnimation.fillMode = kCAFillModeForwards;
fillMode的作用就是决定当前对象过了非active时间段的行为. 比如动画开始之前,动画结束之后。如果是一个动画CAAnimation,则需要将其removedOnCompletion设置为NO,要不然fillMode不起作用.
下面来讲各个fillMode的意义
kCAFillModeRemoved 这个是默认值,也就是说当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态
kCAFillModeForwards 当动画结束后,layer会一直保持着动画最后的状态
kCAFillModeBackwards 这个和kCAFillModeForwards是相对的,就是在动画开始前,你只要将动画加入了一个layer,layer便立即进入动画的初始状态并等待动画开始.你可以这样设定测试代码,将一个动画加入一个layer的时候延迟5秒执行.然后就会发现在动画没有开始的时候,只要动画被加入了layer,layer便处于动画初始状态
kCAFillModeBoth 理解了上面两个,这个就很好理解了,这个其实就是上面两个的合成.动画加入后开始之前,layer便处于动画初始状态,动画结束后layer保持动画最后的状态.
前几天做动画,使用到了CATransform3D ,由于没有学过计算机图形学,矩阵中m11--m44的各个含义都不清楚,经过几天研究总结如下:(供和我一样的菜鸟学习)
-
struct CATransform3D
-
{
-
CGFloat m11(x缩放), m12(y切变), m13(), m14() ;
-
CGFloat m21(x切变), m22(y缩放), m23(), m24() ;
-
CGFloat m31(), m32(), m33(), m34(透视效果,要操作的这个对象要有旋转的角度,否则没有效果。当然,z方向上得有变化才会有透视效果) ;
-
CGFloat m41(x平移), m42(y平移), m43(z平移), m44() ;
-
} ;
ps:
- 整体比例变换时,也就是m11==m22时,若m33>1,图形整体缩小,若0<m33<1,图形整体放大,若m33<0,发生关于原点的对称等比变换。
- 单设m12或m21的时候是切变效果,当【m12=角度】和【m21=-角度】的时候就是旋转效果了。两个角度值相同。
- ()空的地方以后补充。
- 还有,要想使用CATransform3D,必须在工程里导入QuartzCore.framework。然后在文件中
#import <QuartzCore/CATransform3D.h>。
iphone 透视效果(perspective)
-
CATransform3D transform
= CATransform3DIdentity ; -
transform. m34
= 0.0005 ; // 透视效果 -
transform
= CATransform3DRotate (transform , (M_PI / 180 * 40 ) , 0 , 1 , 0 ) ; -
[piece. layer
setTransform :transform ] ;
第二行一定要写在第三行的前面!自己理解!
//
// ViewController.m
// test_scanAnimation_01
//
// Created by admin on 1/13/16.
// Copyright © 2016 jeffasd. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UIImageView *_bgImageView;
UIImageView *_scanningImageView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *bgImage = [UIImage imageNamed:@"zapya_connect_radar"];
NSLog(@"the bgImage size is %@", NSStringFromCGSize(bgImage.size));
_bgImageView = [UIImageView new];
// _bgImageView.frame = CGRectMake(0, 200, self.view.frame.size.width, 300);
_bgImageView.frame = CGRectMake(0, 200, bgImage.size.width, bgImage.size.height);
_bgImageView.backgroundColor = [UIColor redColor];
[self.view addSubview:_bgImageView];
_bgImageView.image = bgImage;
UIImage *scanningImage = [UIImage imageNamed:@"zapya_connect_radar_scanning"];
_scanningImageView = [UIImageView new];
_scanningImageView.frame = _bgImageView.frame;
_scanningImageView.image = scanningImage;
[self.view addSubview:_scanningImageView];
CABasicAnimation *scannigAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
// angle:旋转的弧度,所以要把角度转换成弧度:角度 * M_PI / 180。
CATransform3D transform = CATransform3DMakeRotation(90*M_PI/180, 0, 0, 1);//顺时针旋转
transform.m34 = 0.05;// 透视效果
// transform.autoreverses = YES;
NSValue *value = [NSValue valueWithCATransform3D:transform];
[scannigAnimation setToValue:value];
scannigAnimation.autoreverses = NO;//原路返回动画一遍
scannigAnimation.duration = 2.0;
scannigAnimation.repeatCount = HUGE_VALF;
//basicAnimation.repeatCount=HUGE_VALF;//设置重复次数,HUGE_VALF可看做无穷大,起到循环动画的效果
// basicAnimation.removedOnCompletion=NO;//运行一次是否移除动画
scannigAnimation.fillMode = kCAFillModeBackwards;
scannigAnimation.cumulative = YES;
scannigAnimation.removedOnCompletion = NO;
scannigAnimation.delegate = self;
[_scanningImageView.layer addAnimation:scannigAnimation forKey:nil];
}
#pragma mark - 动画代理方法
#pragma mark 动画开始
-(void)animationDidStart:(CAAnimation *)anim{
// NSLog(@"animation(%@) start.\r_layer.frame=%@",anim,NSStringFromCGRect(_layer.frame));
// NSLog(@"%@",[_layer animationForKey:@"KCBasicAnimation_Translation"]);//通过前面的设置的key获得动画
NSLog(@"%s", __func__);
}
#pragma mark 动画结束
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
// NSLog(@"animation(%@) stop.\r_layer.frame=%@",anim,NSStringFromCGRect(_layer.frame));
// _layer.position=[[anim valueForKey:@"KCBasicAnimationLocation"] CGPointValue];
NSLog(@"%s", __func__);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
前几天做动画,使用到了CATransform3D ,由于没有学过计算机图形学,矩阵中m11--m44的各个含义都不清楚,经过几天研究总结如下:(供和我一样的菜鸟学习)
-
struct CATransform3D
-
{
-
CGFloat m11(x缩放), m12(y切变), m13(), m14() ;
-
CGFloat m21(x切变), m22(y缩放), m23(), m24() ;
-
CGFloat m31(), m32(), m33(), m34(透视效果,要操作的这个对象要有旋转的角度,否则没有效果。当然,z方向上得有变化才会有透视效果) ;
-
CGFloat m41(x平移), m42(y平移), m43(z平移), m44() ;
-
} ;
ps:
- 整体比例变换时,也就是m11==m22时,若m33>1,图形整体缩小,若0<m33<1,图形整体放大,若m33<0,发生关于原点的对称等比变换。
- 单设m12或m21的时候是切变效果,当【m12=角度】和【m21=-角度】的时候就是旋转效果了。两个角度值相同。
- ()空的地方以后补充。
- 还有,要想使用CATransform3D,必须在工程里导入QuartzCore.framework。然后在文件中
#import <QuartzCore/CATransform3D.h>。
iphone 透视效果(perspective)
-
CATransform3D transform
= CATransform3DIdentity ; -
transform. m34
= 0.0005 ; // 透视效果 -
transform
= CATransform3DRotate (transform , (M_PI / 180 * 40 ) , 0 , 1 , 0 ) ; -
[piece. layer
setTransform :transform ] ;
第二行一定要写在第三行的前面!自己理解!
//
// ViewController.m
// test_scanAnimation_01
//
// Created by admin on 1/13/16.
// Copyright © 2016 jeffasd. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UIImageView *_bgImageView;
UIImageView *_scanningImageView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *bgImage = [UIImage imageNamed:@"zapya_connect_radar"];
NSLog(@"the bgImage size is %@", NSStringFromCGSize(bgImage.size));
_bgImageView = [UIImageView new];
// _bgImageView.frame = CGRectMake(0, 200, self.view.frame.size.width, 300);
_bgImageView.frame = CGRectMake(0, 200, bgImage.size.width, bgImage.size.height);
_bgImageView.backgroundColor = [UIColor redColor];
[self.view addSubview:_bgImageView];
_bgImageView.image = bgImage;
UIImage *scanningImage = [UIImage imageNamed:@"zapya_connect_radar_scanning"];
_scanningImageView = [UIImageView new];
_scanningImageView.frame = _bgImageView.frame;
_scanningImageView.image = scanningImage;
[self.view addSubview:_scanningImageView];
CABasicAnimation *scannigAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
// angle:旋转的弧度,所以要把角度转换成弧度:角度 * M_PI / 180。
CATransform3D transform = CATransform3DMakeRotation(90*M_PI/180, 0, 0, 1);//顺时针旋转
transform.m34 = 0.05;// 透视效果
// transform.autoreverses = YES;
NSValue *value = [NSValue valueWithCATransform3D:transform];
[scannigAnimation setToValue:value];
scannigAnimation.autoreverses = NO;//原路返回动画一遍
scannigAnimation.duration = 2.0;
scannigAnimation.repeatCount = HUGE_VALF;
//basicAnimation.repeatCount=HUGE_VALF;//设置重复次数,HUGE_VALF可看做无穷大,起到循环动画的效果
// basicAnimation.removedOnCompletion=NO;//运行一次是否移除动画
scannigAnimation.fillMode = kCAFillModeBackwards;
scannigAnimation.cumulative = YES;
scannigAnimation.removedOnCompletion = NO;
scannigAnimation.delegate = self;
[_scanningImageView.layer addAnimation:scannigAnimation forKey:nil];
}
#pragma mark - 动画代理方法
#pragma mark 动画开始
-(void)animationDidStart:(CAAnimation *)anim{
// NSLog(@"animation(%@) start.\r_layer.frame=%@",anim,NSStringFromCGRect(_layer.frame));
// NSLog(@"%@",[_layer animationForKey:@"KCBasicAnimation_Translation"]);//通过前面的设置的key获得动画
NSLog(@"%s", __func__);
}
#pragma mark 动画结束
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
// NSLog(@"animation(%@) stop.\r_layer.frame=%@",anim,NSStringFromCGRect(_layer.frame));
// _layer.position=[[anim valueForKey:@"KCBasicAnimationLocation"] CGPointValue];
NSLog(@"%s", __func__);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end