animation - 6
2015-12-28 18:04
465 查看
收集几个学习中用到的animation例子,都是结合移动,缩放,旋转,透明度等的常用炫酷实现。
转载于:http://www.cnblogs.com/pengyingh/articles/2396032.html
#import "LBCoreAnimationViewController.h"
@interface LBCoreAnimationViewController ()
@property (nonatomic, strong) UIImageView* imageView;
@end
@implementation LBCoreAnimationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView = [[UIImageView alloc] init];
[self.imageView setFrame:CGRectMake(30, 30, 80, 80)];
[self.imageView setImage:[UIImage imageNamed:@"loading_monkey"]];
[self.view addSubview:self.imageView];
UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(0, 0, 50, 50)];
[button1 setCenter:CGPointMake(self.view.frame.size.width/3, self.view.center.y)];
[button1 setBackgroundColor:[UIColor redColor]];
[button1 setTag:111];
[button1 addTarget:self action:@selector(buttonClicled:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
- (void)buttonClicled:(id)sender
{
UIButton* button = (UIButton*)sender;
//向右下角缩小移动.
if (button.tag == 111)
{
CGPoint fromPoint = self.imageView.center;
//路径曲线,由贝塞曲线来绘制.
UIBezierPath* movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:fromPoint];
CGPoint toPoint = CGPointMake(300, 460);
[movePath addQuadCurveToPoint:toPoint controlPoint:CGPointMake(toPoint.x, fromPoint.y)]; //保持原始的y.
//关键帧.
//用 + animationWithKeyPath 的方法是根据参数的keyPath来返回的.一对一绑定与关键路径的.
CAKeyframeAnimation* moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
//旋转变化.
CABasicAnimation* scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
//x.y轴缩小到0.1,z轴不变
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;
//透明度变化.
CABasicAnimation* opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES;
//关键帧,basic旋转,basic透明度组合执行.
CAAnimationGroup* animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
animGroup.duration = 1;
//这一句就说明了层是构建动画的一个重要原因.
[self.imageView.layer addAnimation:animGroup forKey:nil];
}
}
@end
效果是图像从原始态做右抛物线缩小并且随着缩小而变得透明,形成一个抛物状的动画。但是alpha这部分是没有明显的变化的哦,这个将会去找到为什么呢!!
试着改写一下,使得点击一下从小向右上角做抛物线的相反效果吧!
转载于:http://www.cnblogs.com/pengyingh/articles/2396032.html
#import "LBCoreAnimationViewController.h"
@interface LBCoreAnimationViewController ()
@property (nonatomic, strong) UIImageView* imageView;
@end
@implementation LBCoreAnimationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView = [[UIImageView alloc] init];
[self.imageView setFrame:CGRectMake(30, 30, 80, 80)];
[self.imageView setImage:[UIImage imageNamed:@"loading_monkey"]];
[self.view addSubview:self.imageView];
UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(0, 0, 50, 50)];
[button1 setCenter:CGPointMake(self.view.frame.size.width/3, self.view.center.y)];
[button1 setBackgroundColor:[UIColor redColor]];
[button1 setTag:111];
[button1 addTarget:self action:@selector(buttonClicled:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
- (void)buttonClicled:(id)sender
{
UIButton* button = (UIButton*)sender;
//向右下角缩小移动.
if (button.tag == 111)
{
CGPoint fromPoint = self.imageView.center;
//路径曲线,由贝塞曲线来绘制.
UIBezierPath* movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:fromPoint];
CGPoint toPoint = CGPointMake(300, 460);
[movePath addQuadCurveToPoint:toPoint controlPoint:CGPointMake(toPoint.x, fromPoint.y)]; //保持原始的y.
//关键帧.
//用 + animationWithKeyPath 的方法是根据参数的keyPath来返回的.一对一绑定与关键路径的.
CAKeyframeAnimation* moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
//旋转变化.
CABasicAnimation* scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
//x.y轴缩小到0.1,z轴不变
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;
//透明度变化.
CABasicAnimation* opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES;
//关键帧,basic旋转,basic透明度组合执行.
CAAnimationGroup* animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
animGroup.duration = 1;
//这一句就说明了层是构建动画的一个重要原因.
[self.imageView.layer addAnimation:animGroup forKey:nil];
}
}
@end
效果是图像从原始态做右抛物线缩小并且随着缩小而变得透明,形成一个抛物状的动画。但是alpha这部分是没有明显的变化的哦,这个将会去找到为什么呢!!
试着改写一下,使得点击一下从小向右上角做抛物线的相反效果吧!
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- Android开发之图形图像与动画(二)Animation实现图像的渐变/缩放/位移/旋转
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- Android开发重写Animation实现下拉图片后弹射回去效果示例
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法