ios动画
来源:互联网 发布:百度广告联盟 知乎 编辑:程序博客网 时间:2024/05/16 19:02
基本路径动画
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"position"];
animation.fromValue = [NSValuevalueWithCGPoint:bananaLayer.position];
CGPoint toPoint = bananaLayer.position;
toPoint.x += 180;
animation.toValue = [NSValuevalueWithCGPoint:toPoint];
CABasicAnimation *rotateAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];
rotateAnimation.fromValue = [NSNumbernumberWithFloat:0.0];
rotateAnimation.toValue = [NSNumbernumberWithFloat:1.0 * M_PI];
CABasicAnimation *scaoleAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
scaoleAnimation.duration = 0.5;
scaoleAnimation.autoreverses = YES;
scaoleAnimation.fromValue = [NSNumbernumberWithFloat:1.0];
scaoleAnimation.toValue = [NSNumbernumberWithFloat:1.5];
//简单的移动
CABasicAnimation *theAnimation1; //定义动画
theAnimation1=[CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];
theAnimation1.fromValue=[NSNumbernumberWithFloat:0];
theAnimation1.toValue=[NSNumbernumberWithFloat:-100];
CAAnimationGroup *group = [CAAnimationGroupanimation];
group.autoreverses = YES;
group.duration = 1.0;
group.animations = [NSArrayarrayWithObjects:animation, scaoleAnimation,theAnimation1, nil];
group.repeatCount = NSNotFound;
CABasicAnimation *boundsAnimation = [CABasicAnimationanimationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValuevalueWithCGRect:transitionLayer.bounds];
boundsAnimation.toValue = [NSValuevalueWithCGRect:CGRectZero];
//类似于透明度的东东
CABasicAnimation *opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = [NSNumbernumberWithFloat:1.0];
opacityAnimation.toValue = [NSNumbernumberWithFloat:0.5];
[bananaLayeraddAnimation:group forKey:@"move"];
关键帧动画
self.backgroundColor = [UIColorwhiteColor];
path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 20.0, 40.0);
for (NSUInteger i = 0; i < 10; i++) {
CGFloat x = (i % 2) ? 20.0 : self.bounds.size.width - 20.0;
CGFloat y = 40.0 + 30.0 * (i + 1);
//CGPathAddLineToPoint(path, NULL, x, y);
CGPathAddArcToPoint(path, NULL, x, y, x, y + 20.0, 10.0);
}
spot = [[ZBLayoutLayeralloc] init];
spot.bounds = CGRectMake(0.0, 0.0, 30.0, 30.0);
spot.color = [UIColorredColor];
[self.layeraddSublayer:spot];
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
animation.duration = 5.0;
animation.path = path;
animation.repeatCount = NSUIntegerMax;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[spotaddAnimation:animation forKey:@"move"];
动画停止代理
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
if ([theAnimation isEqual:[transitionLayeranimationForKey:@"move"]]) {
[transitionLayerremoveFromSuperlayer];
[transitionLayerremoveAllAnimations];
}
}
在layer设置一些变量时,似乎就直接默认有动画,如果想去掉这个动画的话,可以采用以下代码
[CATransactionbegin];
[CATransactionsetValue:(id)kCFBooleanTrueforKey:kCATransactionDisableActions];
//以下是自己的代码
transitionLayer.opacity = 1.0;
transitionLayer.contents = (id)aCell.imageView.image.CGImage;
transitionLayer.frame = [[UIApplicationsharedApplication].keyWindowconvertRect:aCell.imageView.boundsfromView:aCell.imageView];
[[UIApplicationsharedApplication].keyWindow.layeraddSublayer:transitionLayer];
[CATransactioncommit];
这个应该也可以
[CATransactionsetDisableActions:actionsSwitch.on];
设置相对复杂点的起始值
CABasicAnimation *transformAnimation = [CABasicAnimationanimationWithKeyPath:@"transform"];
transformAnimation.fromValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];
transformAnimation.toValue = [NSValuevalueWithCATransform3D:CATransform3DMakeRotation(DEGREES_TO_RADIANS(85), 0, 1, 1)];
transformAnimation.duration = 1.5;
transformAnimation.autoreverses = YES;
transformAnimation.repeatCount = HUGE_VALF;
transformAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"position"];
animation.fromValue = [NSValuevalueWithCGPoint:bananaLayer.position];
CGPoint toPoint = bananaLayer.position;
toPoint.x += 180;
animation.toValue = [NSValuevalueWithCGPoint:toPoint];
CABasicAnimation *rotateAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];
rotateAnimation.fromValue = [NSNumbernumberWithFloat:0.0];
rotateAnimation.toValue = [NSNumbernumberWithFloat:1.0 * M_PI];
CABasicAnimation *scaoleAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
scaoleAnimation.duration = 0.5;
scaoleAnimation.autoreverses = YES;
scaoleAnimation.fromValue = [NSNumbernumberWithFloat:1.0];
scaoleAnimation.toValue = [NSNumbernumberWithFloat:1.5];
//简单的移动
CABasicAnimation *theAnimation1; //定义动画
theAnimation1=[CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];
theAnimation1.fromValue=[NSNumbernumberWithFloat:0];
theAnimation1.toValue=[NSNumbernumberWithFloat:-100];
CAAnimationGroup *group = [CAAnimationGroupanimation];
group.autoreverses = YES;
group.duration = 1.0;
group.animations = [NSArrayarrayWithObjects:animation, scaoleAnimation,theAnimation1, nil];
group.repeatCount = NSNotFound;
CABasicAnimation *boundsAnimation = [CABasicAnimationanimationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValuevalueWithCGRect:transitionLayer.bounds];
boundsAnimation.toValue = [NSValuevalueWithCGRect:CGRectZero];
//类似于透明度的东东
CABasicAnimation *opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = [NSNumbernumberWithFloat:1.0];
opacityAnimation.toValue = [NSNumbernumberWithFloat:0.5];
[bananaLayeraddAnimation:group forKey:@"move"];
关键帧动画
self.backgroundColor = [UIColorwhiteColor];
path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 20.0, 40.0);
for (NSUInteger i = 0; i < 10; i++) {
CGFloat x = (i % 2) ? 20.0 : self.bounds.size.width - 20.0;
CGFloat y = 40.0 + 30.0 * (i + 1);
//CGPathAddLineToPoint(path, NULL, x, y);
CGPathAddArcToPoint(path, NULL, x, y, x, y + 20.0, 10.0);
}
spot = [[ZBLayoutLayeralloc] init];
spot.bounds = CGRectMake(0.0, 0.0, 30.0, 30.0);
spot.color = [UIColorredColor];
[self.layeraddSublayer:spot];
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
animation.duration = 5.0;
animation.path = path;
animation.repeatCount = NSUIntegerMax;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[spotaddAnimation:animation forKey:@"move"];
动画停止代理
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
if ([theAnimation isEqual:[transitionLayeranimationForKey:@"move"]]) {
[transitionLayerremoveFromSuperlayer];
[transitionLayerremoveAllAnimations];
}
}
在layer设置一些变量时,似乎就直接默认有动画,如果想去掉这个动画的话,可以采用以下代码
[CATransactionbegin];
[CATransactionsetValue:(id)kCFBooleanTrueforKey:kCATransactionDisableActions];
//以下是自己的代码
transitionLayer.opacity = 1.0;
transitionLayer.contents = (id)aCell.imageView.image.CGImage;
transitionLayer.frame = [[UIApplicationsharedApplication].keyWindowconvertRect:aCell.imageView.boundsfromView:aCell.imageView];
[[UIApplicationsharedApplication].keyWindow.layeraddSublayer:transitionLayer];
[CATransactioncommit];
这个应该也可以
[CATransactionsetDisableActions:actionsSwitch.on];
设置相对复杂点的起始值
CABasicAnimation *transformAnimation = [CABasicAnimationanimationWithKeyPath:@"transform"];
transformAnimation.fromValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];
transformAnimation.toValue = [NSValuevalueWithCATransform3D:CATransform3DMakeRotation(DEGREES_TO_RADIANS(85), 0, 1, 1)];
transformAnimation.duration = 1.5;
transformAnimation.autoreverses = YES;
transformAnimation.repeatCount = HUGE_VALF;
transformAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- iOS动画 核心动画
- iOS动画 UIView动画
- iOS动画 CATransition动画
- iOS 动画 UIView动画
- iOS动画-基础动画
- ios 动画
- IOS动画
- Ios 动画
- ios动画
- IOS 动画
- iOS动画
- ios动画
- ios动画
- iOS动画
- iOS 动画
- ios 动画
- iOS 动画
- iOS 动画
- mlp.py解析(Multilayer Perceptron)
- 移动(cmpp2.0/cmpp3.0)、联通(sgip1.2)、电信(smgp3.0)的长短信实现的经验
- 关于下拉更新框架 EGORefreshTableHeaderView在Xcode4.2中, ARC下面的使用
- 蓝牙设计问与答
- sizeof,终极无惑(上)
- ios动画
- 相信在这个论坛混的大部分是知道西电的,这是西电大一结束的学生对学校的一点思考
- [2013.7.22]工作日志
- 开发遇到的问题or知识点
- 第一次实习面试感受----苦逼程序员生活初体验
- HDU 2083 简易版之最短距离
- Median of Two Sorted Arrays(找两个排序数组的中位数,二分法)
- Palindrome Partitioning II(找给定字符串分割次数获取回文字串, 动态规划)
- poj 1113 Wall-----凸包