CAAnimation动画/CAAnimation Group

动画分隐式动画和显式动画


CAAnimatione采用了CAMediaTiming协议,可以调整时间,包括持续时间,速度,重复次数;采用了CAAction协议,可以通过响应动作的方式来显示动画.

CAAnimation的一些派生类:
CATransition 提供渐变效果:(推拉push效果,消退fade效果,揭开reveal效果)
CAAnimationGroup 允许多个动画同时播放
CABasicAnimation 提供了对单一动画的实现
CAKeyframeAnimation 关键桢动画,可以定义行动路线
CAConstraint 约束类,在布局管理器类中用它来设置属性
CAConstraintLayoutManager 约束布局管理器,是用来将多个CALayer进行布局的.各个CALayer是通过名称来区分,而布局属性是通过CAConstraint来设置的.
CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务.


事务管理(Transactions)
事务分两种:
1.隐式事务(implicit transaction)
除显式事务外,任何对于CALayer属性的修改,都是隐式事务.这样的事务会在run-loop中被提交.
如:
theLayer.opacity = 0.0;
theLayer.zPosition = -200;
theLayer.position = CGPointMake(0.0, 0.0);

2.显式事务(explicit transaction)
a. 通过明确的调用begin,commit来提交动画.优点是可以同时修改多个Layer的属性.
如:
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
                               forKey:kCATransactionDisableActions];
[aLayer removeFromSuperlayer];
[CATransaction commit];

b.可以重置持续时间
可以在begin,commit对中临时修改动画持续时间.
[CATransaction begin]
[CATransaction setValue:[NSNumber numberWithFloat:10.0f]
                               forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit];

c.事务可以嵌套.
如:
//第一层嵌套
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.0f]
                             forKey:kCATransactionAnimationDuration];
theLayer.position = CGPointMake(0.0, 0.0);
//第二层嵌套
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:5.0f]
                               forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit];
[CATransaction commit];



布局管理器示例如下:
//创建和设置一个布局管理器
theLayer.layoutManager = [CAConstraintLayoutManager layoutManager];

//创建layerA
CALayer *layerA = [CALayer layer];
layerA.name = @"layerA";

//设置layerA的中点位置等于超类的中点位置
[layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidY
                                                                                       relativeTo:@"superLayer"
                                                                                       attribute:kCAConstraintMidY]];

[layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidX
                                                                                       relativeTo:@"superLayer"
                                                                                       attribute:kCAConstraintMidX]];
[theLayer addSublayer:layerA];

//创建layerB
CALayer *layerB = [CALayer layer];
layerB.name = @"layerB";

//设置layerB的宽度等于layerA的宽度
[layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintWidth
                                                                                       relativeTo:@"LayerA"
                                                                                       attribute:kCAConstraintWidth]];

[layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidX
                                                                                       relativeTo:@"layerA"
                                                                                       attribute:kCAConstraintMidX]];

[theLayer addSublayer:layerB];


转自‘http://hi.baidu.com/iamgleaf/blog/item/38520d949d025107d31b7023.html

//  AnimationView.m

//  AnimationTestV2

//

//  Created by jtone  on 11-8-9.

//  Copyright 2011年__MyCompanyName__. All rights reserved.

//

#import"AnimationView.h"

#import<QuartzCore/QuartzCore.h>

#define kDuaitionOfTimer00.2

#define kDuaitionOfTimer10.2

#define kDuaitionOfTimer20.2

#define kDuaitionOfTimer30.2

#define kDuaitionOfTimer41.1

#define kDisplacementOfTimer110

#define kDisplacementOfTimer210

@implementationAnimationView

CGPoint leftPhoneCenter;

CGPoint contactCenter;

CGPoint rightPhoneCenter;

CGPoint picCenter;



//位置变化动画

- (CAAnimation *)animationMoveFrom:(CGPoint) from To:(CGPoint) to Duration:(CGFloat) duration BeginTime:(CGFloat)beginTime 

{

CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

CGFloat animationDuration = duration;

CGMutablePathRef thePath = CGPathCreateMutable();

CGPathMoveToPoint(thePath, NULL, from.x, from.y);

CGPathAddLineToPoint(thePath, NULL, to.x, to.y);

bounceAnimation.path = thePath;

bounceAnimation.duration = animationDuration;

    bounceAnimation.beginTime = beginTime;

bounceAnimation.repeatCount=0;

bounceAnimation.removedOnCompletion=NO;

bounceAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

CGPathRelease(thePath);

return bounceAnimation;

}


//透明度变化动画

-(CAAnimation *)animationWithOpacityFrom:(CGFloat) from To:(CGFloat) to Duration:(CGFloat) duration BeginTime:(CGFloat)beginTime 

{    

    CABasicAnimation *theAnimation;    

    theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];    

    theAnimation.duration=duration; 

    theAnimation.beginTime = beginTime;    

    theAnimation.repeatCount=0;    

    theAnimation.autoreverses=NO;    

    theAnimation.fromValue=[NSNumber numberWithFloat:from];    

    theAnimation.toValue=[NSNumber numberWithFloat:to];

    

    return theAnimation;

}



-(NSArray *)AnimWithPhone:(CGPoint)phoneCenter Option:(int)option//手机壳动画设置

{

    NSArray *arr = [NSArray arrayWithObjects:

                    [self   animationMoveFrom:phoneCenter  To:CGPointMake(phoneCenter.x+kDisplacementOfTimer1*option,phoneCenter.y)    Duration:kDuaitionOfTimer0 BeginTime:1.5],

                    [self   animationMoveFrom:CGPointMake(phoneCenter.x+kDisplacementOfTimer1*option,phoneCenter.y)    To:phoneCenter  Duration:kDuaitionOfTimer1 BeginTime:1.7],

                    [self   animationMoveFrom:phoneCenter    To:CGPointMake(phoneCenter.x+kDisplacementOfTimer2*option,phoneCenter.y)  Duration:kDuaitionOfTimer2 BeginTime:1.9],

                    [self  animationMoveFrom:CGPointMake(phoneCenter.x+kDisplacementOfTimer2*option,phoneCenter.y)    To:phoneCenter  Duration:kDuaitionOfTimer3 BeginTime:2.1],

                   nil];

   returnarr;

}



-(NSArray *)AnimFromObj:(CGPoint)obj1 ToObj:(CGPoint)obj2 Option:(int)option//图片,联系人动画设置

{

    NSArray *arr = [NSArray arrayWithObjects:

                    [self  animationWithOpacityFrom:0.0To:0.0Duration:1.0BeginTime:0.0],

                    [self  animationWithOpacityFrom:0.0To:1.0Duration:0.3BeginTime:1.0],

                    [self  animationMoveFrom:obj1  To:CGPointMake(obj1.x+kDisplacementOfTimer1*option, obj1.y)    Duration:kDuaitionOfTimer0 BeginTime:1.5],

                    [self  animationMoveFrom:CGPointMake(obj1.x+kDisplacementOfTimer1*option, obj1.y)    To:obj1  Duration:kDuaitionOfTimer1 BeginTime:1.7],

                    [self  animationMoveFrom:obj1    To:CGPointMake(obj1.x+kDisplacementOfTimer2*option,obj1.y)   Duration:kDuaitionOfTimer2 BeginTime:1.9],

                    [self  animationMoveFrom:CGPointMake(obj1.x+kDisplacementOfTimer2*option,obj1.y)     To:obj1  Duration:kDuaitionOfTimer3 BeginTime:2.1],

                    [self  animationMoveFrom:obj1 To:obj2 Duration:kDuaitionOfTimer4 BeginTime:2.4],

                    [self  animationMoveFrom:obj2 To:obj2 Duration:kDuaitionOfTimer4 BeginTime:3.5],

                    [self  animationWithOpacityFrom:1.0To:0.0Duration:0.3BeginTime:3.7],

                   nil];                    

   returnarr;

}




-(CAAnimationGroup *)getAnimGroup //创建动画组

{

    CAAnimationGroup * animGroup  = [CAAnimationGroup animation];

animGroup.delegate            = self;

animGroup.removedOnCompletion = NO;

animGroup.duration  = 4.0;

animGroup.repeatCount  = 1;

animGroup.fillMode  = kCAFillModeForwards;

    return animGroup;

}




-(void)setup//开始动画

{

    leftPhoneCenter    = CGPointMake(leftPhone.frame.origin.x+35, leftPhone.frame.origin.y+55);

    contactCenter         = CGPointMake(contact.frame.origin.x+25, contact.frame.origin.y+25);

    rightPhoneCenter = CGPointMake(rightPhone.frame.origin.x+35, rightPhone.frame.origin.y+55);

    picCenter                 = CGPointMake(picture.frame.origin.x+25,picture.frame.origin.y+25);

    

    contact.hidden = NO;

    picture.hidden = NO;

    

    CAAnimationGroup * mp1 = [self getAnimGroup];

    mp1.animations           = [self AnimWithPhone:leftPhoneCenter Option:-1];

    

    [leftPhone.layer addAnimation:mp1 forKey:@"jtone"];

    [leftPhoneScreen.layer addAnimation:mp1 forKey:@"jtone"];

    

    CAAnimationGroup * mp2 = [self getAnimGroup];

    mp2.animations           = [self AnimWithPhone:rightPhoneCenter Option:1];

    

    [rightPhone.layer addAnimation:mp2 forKey:@"jtone"];

    [rightPhoneScreen.layer addAnimation:mp2 forKey:@"jtone"];

    

    CAAnimationGroup * mp3 = [self getAnimGroup];

    mp3.animations           = [self AnimFromObj:contactCenter ToObj:picCenter Option:-1];

    [contact.layer addAnimation:mp3 forKey:@"jtone"];    

    

    CAAnimationGroup * mp4 = [self getAnimGroup];

    mp4.animations           = [self AnimFromObj:picCenter ToObj:contactCenter Option:1];

    [picture.layer addAnimation:mp4 forKey:@"jtone"];

}



- (void)dealloc

{

    [superdealloc];

}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于/etc/group文件的信息泄露,这可能会导致安全风险,因为该文件包含了系统中所有组的信息。如果未经授权的人员获得了该文件,他们可能会获取到系统中的用户和组的关联关系,从而有可能进行未经授权的访问和权限提升。 为了减少信息泄露的风险,以下是一些建议的措施: 1. 限制对/etc/group文件的访问权限:确保只有授权的用户或管理员才能访问该文件。可以使用适当的文件权限设置来限制对该文件的读取权限。 2. 定期审查和监控:定期审查/etc/group文件,确保其中的组信息是正确且没有异常。同时,设置日志监控,以便及时发现任何对该文件的非授权访问。 3. 加强系统安全措施:确保系统有适当的防火墙、入侵检测系统和安全补丁更新等安全措施,以减少未经授权访问和信息泄露的风险。 4. 实施访问控制策略:使用访问控制列表(ACL)或其他访问控制机制,限制对/etc/group文件的访问。只有需要了解组信息的合法用户才能获得访问权限。 5. 加密和保护备份:如果您需要备份/etc/group文件,确保备份文件的安全性,可以对备份文件进行加密,并将其存储在安全的位置。 总之,保护/etc/group文件的安全对于防止信息泄露和提高系统安全性至关重要。通过限制访问权限、定期审查和监控、加强系统安全措施以及实施访问控制策略,可以降低信息泄露的风险。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值