ios动画
2015-10-16 19:42
393 查看
//
动画分为两种UIView层动画 CALayer层动画。
// UIView层动画分为两种类型:
// 1.属性动画
// 2.过渡动画
//属性动画之block
// [UIView animateWithDuration:1 animations:^{
// self.AView.alpha = 0.3;
// }];
// [UIView animateWithDuration:3 animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// NSLog(@"结束");
// }];
// [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// self.AView.backgroundColor = [UIColor redColor];
// }];
// [UIView animateWithDuration:2 delay:2 usingSpringWithDamping:0.1 initialSpringVelocity:2 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// }];
// 普通翻页效果
UIView *containerView =
self.view.superview;
[UIView
transitionWithView:containerView
duration:2
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.view
removeFromSuperview] ;
[containerView addSubview:XVC.view];
} completion:^(BOOL finished) {
}];
// CAlayer层在做属性动画时
并不是所有的属性都可以做动画 只有属性后面带Animatable的才可以做动画。
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
basicAnimation.duration =
2;
basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);
basicAnimation.toValue = (__bridge
id)([UIColor
redColor].CGColor);
[self.AView.layer
addAnimation:basicAnimation
forKey:@"BS"];
//类似于QQ的弹框的抖动效果
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
CGFloat x =
self.AView.center.x;
CGFloat leftX = x -
10;
CGFloat rightX = x +
10;
NSNumber *X = [NSNumber
numberWithFloat:x];
NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
NSNumber *righty = [NSNumber
numberWithFloat:rightX];
NSArray *values =
@[X,leftx,X,righty,X,leftx,X,righty,X];
keyFrameAnimation.values = values;
[self.AView.layer
addAnimation:keyFrameAnimation
forKey:@"keyFrame"];
CATransition 动画具有方块翻页效果
CATransition *catransition = [CATransition
animation];
// 1获取self.view.superView
UIView *view =
self.view.superview;
catransition.type =
@"cube";
catransition.duration =
3;
catransition.startProgress =
0.3; //
开始动画
catransition.endProgress =
0.8; //
结束动画
// 2给self.view.superView添加动画
[view.layer
addAnimation:catransition
forKey:@"catransition"];
// 3移除原来的View,添加新的View
[self.view
removeFromSuperview];
XViewController *XVC = [self.storyboard
instantiateViewControllerWithIdentifier:@"X"];
[view addSubview:XVC.view];
CAAnimationGroup可融合前面的动画 做出多动画效果
CAAnimationGroup *group = [CAAnimationGroup
animation];
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
basicAnimation.duration =
2;
basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
CGFloat x =
self.AView.center.x;
CGFloat leftX = x -
10;
CGFloat rightX = x +
10;
NSNumber *X = [NSNumber
numberWithFloat:x];
NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
NSNumber *righty = [NSNumber
numberWithFloat:rightX];
NSArray *values =
@[X ,leftx,X,righty,X,leftx,X,righty,X];
keyFrameAnimation.values = values;
group.duration =
2;
group.animations =
@[basicAnimation,keyFrameAnimation];
[self.AView.layer
addAnimation:group forKey:@"group"];
动画分为两种UIView层动画 CALayer层动画。
// UIView层动画分为两种类型:
// 1.属性动画
// 2.过渡动画
//属性动画之block
// [UIView animateWithDuration:1 animations:^{
// self.AView.alpha = 0.3;
// }];
// [UIView animateWithDuration:3 animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// NSLog(@"结束");
// }];
// [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// self.AView.backgroundColor = [UIColor redColor];
// }];
// [UIView animateWithDuration:2 delay:2 usingSpringWithDamping:0.1 initialSpringVelocity:2 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
// self.AView.backgroundColor = [UIColor grayColor];
// self.AView.bounds = CGRectMake(0, 0, 100, 100);
// } completion:^(BOOL finished) {
// }];
// 普通翻页效果
UIView *containerView =
self.view.superview;
[UIView
transitionWithView:containerView
duration:2
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.view
removeFromSuperview] ;
[containerView addSubview:XVC.view];
} completion:^(BOOL finished) {
}];
// CAlayer层在做属性动画时
并不是所有的属性都可以做动画 只有属性后面带Animatable的才可以做动画。
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
basicAnimation.duration =
2;
basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);
basicAnimation.toValue = (__bridge
id)([UIColor
redColor].CGColor);
[self.AView.layer
addAnimation:basicAnimation
forKey:@"BS"];
//类似于QQ的弹框的抖动效果
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
CGFloat x =
self.AView.center.x;
CGFloat leftX = x -
10;
CGFloat rightX = x +
10;
NSNumber *X = [NSNumber
numberWithFloat:x];
NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
NSNumber *righty = [NSNumber
numberWithFloat:rightX];
NSArray *values =
@[X,leftx,X,righty,X,leftx,X,righty,X];
keyFrameAnimation.values = values;
[self.AView.layer
addAnimation:keyFrameAnimation
forKey:@"keyFrame"];
CATransition 动画具有方块翻页效果
CATransition *catransition = [CATransition
animation];
// 1获取self.view.superView
UIView *view =
self.view.superview;
catransition.type =
@"cube";
catransition.duration =
3;
catransition.startProgress =
0.3; //
开始动画
catransition.endProgress =
0.8; //
结束动画
// 2给self.view.superView添加动画
[view.layer
addAnimation:catransition
forKey:@"catransition"];
// 3移除原来的View,添加新的View
[self.view
removeFromSuperview];
XViewController *XVC = [self.storyboard
instantiateViewControllerWithIdentifier:@"X"];
[view addSubview:XVC.view];
CAAnimationGroup可融合前面的动画 做出多动画效果
CAAnimationGroup *group = [CAAnimationGroup
animation];
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
basicAnimation.duration =
2;
basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
CGFloat x =
self.AView.center.x;
CGFloat leftX = x -
10;
CGFloat rightX = x +
10;
NSNumber *X = [NSNumber
numberWithFloat:x];
NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
NSNumber *righty = [NSNumber
numberWithFloat:rightX];
NSArray *values =
@[X ,leftx,X,righty,X,leftx,X,righty,X];
keyFrameAnimation.values = values;
group.duration =
2;
group.animations =
@[basicAnimation,keyFrameAnimation];
[self.AView.layer
addAnimation:group forKey:@"group"];
相关文章推荐
- ios presentViewController:destinationView跳转后黑屏问题
- 我的IOS学习历程-第七天
- iOS学习之iOS沙盒(sandbox)机制和文件操作
- iOS沙盒目录结构解析
- iOS开发者账号总结(三)
- IOS开发者账号的相关配置-子账号(二)
- iOS不使用JSONKit做Dic到JsonString的转换
- 写给iOS小白的MVVM教程(一): 从MVC到MVVM之一个典型的MVC应用场景
- 写给iOS小白的MVVM教程(一): 从MVC到MVVM之一个典型的MVC应用场景
- iOS:核心动画之基本动画CABasicAnimation
- air mobile andriod ios 页面加载控件
- iOS 蓝牙
- iOS9 广告拦截 CONTENT BLOCKER
- ios8 桌面图标圆角数字显示未读消息个数
- iOS mark地址
- ios 下CGImageCreateWithImageInRect 内存泄露
- iOS 工程引用
- iOS开发多线程篇—自定义NSOperation
- iOS开发多线程篇—NSOperation基本操作
- iOS开发多线程篇—NSOperation简单介绍