iOS 动画分类浅析
2014-08-12 20:55
323 查看
别人的世界如何旋转,移动我不知道,也不想猜测。先把自己的想做的做了就好。just do it,just do
I T。O(∩_∩)O~。
很多代码直接摘自下载的例子。手比较懒 。
view负责交互,layer负责展示,一个uiview默认有一个layer,可以添加多个layer。
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
+ (void)transitionFromView:(UIView *)fromView
toView:(UIView *)toView duration:+(NSTimeInterval)duration
options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion ;//根据设定options
可以指定界面是隐藏还是删除
bas.duration=1;
bas.delegate=self;
bas.fromValue=[NSNumber numberWithInteger:0];
bas.toValue=[NSNumber numberWithInteger:1];
[layer addAnimation:bas forKey:@"key”];
animation.duration = 5.0;
animation.path = path;
animation.repeatCount = NSUIntegerMax;
animation.autoreverses = YES;//动画执行完之后是不是原路返回。
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[spotlayer addAnimation:animation forKey:@"move"];
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"];
[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”];
You can not specify a structure field key path using Objective-C 2.0 properties. This will not work:
Instead you must use
shown below:
I T。O(∩_∩)O~。
很多代码直接摘自下载的例子。手比较懒 。
view负责交互,layer负责展示,一个uiview默认有一个layer,可以添加多个layer。
1. 使用UIView的类方法,去实现动画。
+ (void)animateWithDuration:(NSTimeInterval)durationanimations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
+ (void)transitionFromView:(UIView *)fromView
toView:(UIView *)toView duration:+(NSTimeInterval)duration
options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion ;//根据设定options
可以指定界面是隐藏还是删除
2.也可以直接改变layer。
我们可以使用很多方法添加动画。这些动画都是继承自CAAnimation。常用的keypath看最下边的介绍。CABasicAnimation
CABasicAnimation *bas=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];bas.duration=1;
bas.delegate=self;
bas.fromValue=[NSNumber numberWithInteger:0];
bas.toValue=[NSNumber numberWithInteger:1];
[layer addAnimation:bas forKey:@"key”];
CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];animation.duration = 5.0;
animation.path = path;
animation.repeatCount = NSUIntegerMax;
animation.autoreverses = YES;//动画执行完之后是不是原路返回。
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[spotlayer addAnimation:animation forKey:@"move"];
CATransition
CATransition *t = [CATransition animation];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 begin];//设置层的时候,这样保证此刻是在一个线程中实现的。[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 介绍:
rotation.x | The rotation, in radians, in the x axis. |
rotation.y | The rotation, in radians, in the y axis. |
rotation.z | The rotation, in radians, in the z axis. |
rotation | The rotation, in radians, in the z axis. This is identical to setting the rotation.zfield. |
scale.x | Scale factor for the x axis. |
scale.y | Scale factor for the y axis. |
scale.z | Scale factor for the z axis. |
scale | Average of all three scale factors. |
translation.x | Translate in the x axis. |
translation.y | Translate in the y axis. |
translation.z | Translate in the z axis. |
translation | Translate in the x and y axis. Value is an NSSize or CGSize. |
CGPointexposes the following fields:
Structure Field | Description |
---|---|
x | The x component of the point. |
y | The y component of the point. |
CGSizeexposes the following fields:
Structure Field | Description |
---|---|
width | The width component of the size. |
height | The height component of the size. |
CGRectexposes the following fields:
Structure Field | Description |
---|---|
origin | The origin of the rectangle as a CGPoint. |
origin.x | The x component of the rectangle origin. |
origin.y | The y component of the rectangle origin. |
size | The size of the rectangle as a CGSize. |
size.width | The width component of the rectangle size. |
size.height | The height component of the rectangle size. |
myLayer.transform.rotation.x=0; |
setValue:forKeyPath:or
valueForKeyPath:as
shown below:
[myLayer setValue:[NSNumber numberWithInt:0] forKeyPath:@"transform.rotation.x"]; |
相关文章推荐
- iOS动画浅析
- iOS动画浅析
- iOS动画浅析
- iOS 属性动画的一个分类:CABasicAnimation 基本动画(没有真正修改属性值)
- CABasicAnimation 基本动画 分类: ios技术 2015-07-16 17:10 132人阅读 评论(0) 收藏
- iOS动画浅析
- iOS核心动画--浅析三个动画的实现
- ios 动画浅析
- iOS动画特效 分类: ios技术 2015-05-15 16:29 311人阅读 评论(0) 收藏
- iOS中各种动画分类
- iOS动画浅析
- iOS 动画浅析
- iOS动画浅析-CATransition
- iOS动画浅析
- ios 加载进度动画——圆型加载进度方式浅析
- iOS动画浅析-CATransition
- JS简单动画封装浅析
- iOS的动画效果类型及实现方法
- IOS中如何模拟UINavigationController的Slide动画
- Silverlight中动画的性能浅析