1. 使用UIView的类方法,去实现动画。
2.也可以直接改变layer。
CABasicAnimation
bas.duration=1;
bas.delegate=self;
bas.fromValue=[NSNumber numberWithInteger:0];
bas.toValue=[NSNumber numberWithInteger:1];
[layer addAnimation:bas forKey:@"key”];
CAKeyframeAnimation
animation.duration = 5.0;
animation.path = path;
animation.repeatCount = NSUIntegerMax;
animation.autoreverses = YES;//动画执行完之后是不是原路返回。
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut ];
[spotlayer addAnimation:animation forKey: @"move" ];
CATransition
t.type = typeController.selectedType;//飞入
t.subtype = subtypeController.selectedSubtype;//从左边
t.duration = 1.5;
t.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];//移动时候的速度由它控制。
self.view1.layer.contents = (id)[UIImage imageNamed:[images objectAtIndex:imageIndex]].CGImage;
[self.view1.layer addAnimation:t forKey:@"Transition"];
CAAnimationGroup
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
transitionLayer.opacity = 1.0;
transitionLayer.contents = (id)aCell.imageView.image.CGImage;
transitionLayer.frame = [[UIApplication sharedApplication].keyWindow convertRect:aCell.imageView.bounds fromView:aCell.imageView];
[[UIApplication sharedApplication].keyWindow.layer addSublayer:transitionLayer];
[CATransaction commit ];
CABasicAnimation *positionAnimation = [ CABasicAnimation animationWithKeyPath : @"position" ];
positionAnimation. fromValue = [ NSValue valueWithCGPoint : transitionLayer . position ];
positionAnimation. toValue = [ NSValue valueWithCGPoint : CGPointZero ];
CABasicAnimation *boundsAnimation = [ CABasicAnimation animationWithKeyPath : @"bounds" ];
boundsAnimation. fromValue = [ NSValue valueWithCGRect : transitionLayer . bounds ];
boundsAnimation. toValue = [ NSValue valueWithCGRect : CGRectZero ];
CABasicAnimation *opacityAnimation = [ CABasicAnimation animationWithKeyPath : @"opacity" ];
opacityAnimation. fromValue = [ NSNumber numberWithFloat : 1.0 ];
opacityAnimation. toValue = [ NSNumber numberWithFloat : 0.5 ];
CABasicAnimation *rotateAnimation = [ CABasicAnimation animationWithKeyPath : @"transform.rotation.z" ];
rotateAnimation. fromValue = [ NSNumber numberWithFloat : 0 * M_PI ];
rotateAnimation. toValue = [ NSNumber numberWithFloat : 2 * M_PI ];
CAAnimationGroup *group = [ CAAnimationGroup animation ];//多个动画一起执行。决定执行的顺序
group. beginTime = CACurrentMediaTime () + 0.25 ;
group. duration = 0.5 ;
group. animations = [ NSArray arrayWithObjects :positionAnimation, boundsAnimation, opacityAnimation, rotateAnimation, nil ];
group. delegate = self ;
group. fillMode = kCAFillModeForwards ;
group. removedOnCompletion = NO ;
[ transitionLayer addAnimation :group forKey : @"move ”];
UIDynamicAnimator
3. keypath 介绍:
| The rotation, in radians, in the x axis. |
| The rotation, in radians, in the y axis. |
| The rotation, in radians, in the z axis. |
| The rotation, in radians, in the z axis. This is identical to setting the |
| Scale factor for the x axis. |
| Scale factor for the y axis. |
| Scale factor for the z axis. |
| Average of all three scale factors. |
| Translate in the x axis. |
| Translate in the y axis. |
| Translate in the z axis. |
| Translate in the x and y axis. Value is an NSSize or CGSize. |
CGPoint
exposes the following fields:
Structure Field | Description |
---|---|
| The x component of the point. |
| The y component of the point. |
CGSize
exposes the following fields:
Structure Field | Description |
---|---|
| The width component of the size. |
| The height component of the size. |
CGRect
exposes the following fields:
Structure Field | Description |
---|---|
| The origin of the rectangle as a |
| The x component of the rectangle origin. |
| The y component of the rectangle origin. |
| The size of the rectangle as a |
| The width component of the rectangle size. |
| The height component of the rectangle size. |
You can not specify a structure field key path using Objective-C 2.0 properties. This will not work:
myLayer.transform.rotation.x=0; |
Instead you must use setValue:forKeyPath:
or valueForKeyPath:
as shown below:
[myLayer setValue:[NSNumber numberWithInt:0] forKeyPath:@"transform.rotation.x"]; |