UI day 22 block动画 CAlayer动画

来源:互联网 发布:feynman 知乎 编辑:程序博客网 时间:2024/06/06 06:56
UIView属性动画可动画的属性:frame center bounds alpha backgroundColor tranform
//修改属性做动画,动画结束后属性修改的结果是真实地作用到视图上,不能恢复到以前的样子

        ios4.0之后使用block块的形式
1.第一种形式 
__blocktypeof(self) welkSelf =self;
    [
UIView animateWithDuration:3animations:^{
       
//1.修改中心点
       
CGPoint center = welkSelf.aninationView.center;
        center.
y += 50;
        welkSelf.
aninationView.center= center;
        welkSelf.
aninationView.alpha= 0.0;//透明度
        welkSelf.
aninationView.transform= CGAffineTransformRotate(welkSelf.aninationView.transform,M_PI_4);//变形
    }];
2.第二种形式
_blocktypeof(self) welkSelf =self;
    [
UIView animateWithDuration:2animations:^{
       
CGPoint center = welkSelf.aninationView.center;
        center.
y += 50;
        welkSelf.
aninationView.center= center;
        welkSelf.
aninationView.transform= CGAffineTransformScale(welkSelf.aninationView.transform,0.5,0.5);
    }
completion:^(BOOLfinished) {
        [welkSelf
makeAnimationBack];
       
    }];

3.第三种形式
 //第三种形式01持续时间02动画执行的延迟时间03设置动画的特效04修改的动画属性05动画执行结束的block
   
   
__block typeof(self) welkSelf =self;
    [
UIView animateWithDuration:2delay:2options:UIViewAnimationOptionAllowAnimatedContentanimations:^{
       
CGPoint center = welkSelf.aninationView.center;
        center.
y += 50;
        welkSelf.
aninationView.center= center;
         welkSelf.
aninationView.transform= CGAffineTransformScale(welkSelf.aninationView.transform,0.5,0.5);
    }
completion:^(BOOLfinished) {
        [welkSelf
makeAnimationBack];
       
    }];
4.第四种形式
第四种形式01动画的持续的时间  02延迟的时间03设置弹簧的强度(0.0 ~1.0)  04设置弹簧的速度05 动画效果 06 改变动画属性写在这里 07 结束动画的时候调用
   
__block typeof(self) welkSelf =self;
    [
UIView animateWithDuration:2delay:1usingSpringWithDamping:0.5initialSpringVelocity:1000options:UIViewAnimationOptionCurveEaseInanimations:^{
       
CGPoint center = welkSelf.bounces.center;
        center.
y += 10;
        welkSelf.
bounces.center= center;
        welkSelf.
bounces.transform= CGAffineTransformScale(welkSelf.bounces.transform,1.5,1.5);
    }
completion:^(BOOLfinished) {
    
CGPoint center =  welkSelf.bounces.center;
        center.
y-=10;
        welkSelf.
bounces.center= center;
        welkSelf.
bounces.transform= CGAffineTransformIdentity;
    }];

                   CAlayer 动画

//UIView的过渡动画
- (
void)handleTrasitionAnimation{
   
__block typeof(self) weakSelf =self;
   
//01对那个视图添加过渡动画  02动画时长
    [
UIView transitionWithView:self.aninationViewduration:1options:UIViewAnimationOptionAllowAnimatedContentanimations:^{
        weakSelf.
aninationView.transform= CGAffineTransformRotate(self.aninationView.transform,M_PI);
    }
completion:nil];
   
}

//CAlayer动画修改layer层的属性,并没有真实做用到这个视图上动画只是一中假象
- (
void)handleLayer{
   
//Calayer动画就是对layer层做动画
   
self.aninationView.layer.borderWidth= 10.0;
   
self.aninationView.layer.borderColor= [UIColorgreenColor].CGColor;
   
self.aninationView.layer.cornerRadius= 100;
   
self.aninationView.clipsToBounds= YES;//这种也可以切除Layer多余的部分
//    self.aninationView.layer.masksToBounds = YES;//这种也可以切除Layer多余的
   
self.aninationView.layer.contents= (id)[UIImageimageNamed:@"6.jpg"].CGImage;
   
//锚点anchorPoint决定layer层上的那个点是position 锚点默认是:(0.5,0.5)根视图的中心点重合
   
//视图以创建出来的时候锚点基本点中心点是重合的
   
self.aninationView.layer.anchorPoint= CGPointMake(0.0,1.0);
   
//    frame.origin.x = position.x - anchorPoint.x * bounds.size.width
//    frame.origin.y = position.y - anchorPoint.y * bounds.size.height
   
   
//基准点position决定当前视图的layer在父视图上的位置,它以父视图的坐标系为准
   
self.aninationView.transform=CGAffineTransformRotate(self.aninationView.transform,M_PI_4);
   
self.aninationView.layer.position= CGPointMake(60,384);
}



//CAlayer的动画基类CAAanimation
//CABasicAnimation
-(
void)handleBasecAnimation
{
   
//CA动画根据KVC的原理,就修改layer的属性,已达到做动画的效果
   
CABasicAnimation*basic = [CABasicAnimationanimationWithKeyPath:@"position.x"];
    basic.
fromValue = @(-80);
    basic.
toValue = @400;
   
//设置动画持续的时间
    basic.
duration = 3.0;
   
//设置动画重复的此时
    basic.
repeatCount= 1000;
    [
self.cloud.layeraddAnimation:basicforKey:nil];
}


//关键贞动画CAKeyframeAnimation
- (
void)handleKeyFrameAnimation{
   
CAKeyframeAnimation*keyFrame = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
   
CGPoint point1 = self.cloud.center;
   
CGPoint point2 = CGPointMake(160,100);
   
CGPoint point3 = CGPointMake(255,self.cloud.center.y);
   
NSValue *value1 = [NSValue valueWithCGPoint:point1];
   
NSValue *value2 = [NSValue valueWithCGPoint:point2];
   
NSValue *value3  = [NSValue valueWithCGPoint:point3];
   
//把一组要播放的动画放到数组中,按顺序放到数组中,此时动画执行的效果,就会按数组中数据的顺序发生变换
 
    keyFrame.
values = @[value1,value2,value3,value1];
    keyFrame.
repeatCount= 1000;
    keyFrame.
duration= 3;
    [
self.cloud.layeraddAnimation:keyFrameforKey:nil];
  
   
}


//过度动画CATransaction
- (
void)handleLayerTransaction{
   
//创建过度动画对象
   
CATransition *transiction = [CATransitionanimation];
   
//配置过度动画的样式
    transiction.
type= @"rippleEffect";
    [
self.view.layeraddAnimation:transictionforKey:nil];//将过度动画添加到layer
   
}

//CAAnimationGroup分组动画
- (
void)handleAnimationGroup{
   
//1.创建第一个关键帧动画,给气球一个运动轨迹
   
CAKeyframeAnimation*keyFramePath = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
   
//贝塞尔曲线
   
//1.制定贝塞尔曲线的半径
   
CGFloat radius = [UIScreen mainScreen].bounds.size.height/2;
   
//01 圆心 02 半径 03 开始的角度 04 结束的角度 05 旋转方向 YES表示顺时针NO表示逆时针
   
UIBezierPath *path = [UIBezierPathbezierPathWithArcCenter:CGPointMake(0, radius) radius:radiusstartAngle:-M_PI_2endAngle:M_PI_2clockwise:YES];
    keyFramePath.
path= path.CGPath;//将贝塞尔曲线作为运动轨迹
   
//2.创建关键帧动画,让气球在运动的时候从小到大在到小的过程
   
CAKeyframeAnimation*keyFrameScale = [CAKeyframeAnimationanimationWithKeyPath:@"transform.scale"];
   
//通过一组数据修改气球的大小
    keyFrameScale.
values= @[@1.0,@1.2,@1.4,@1.6,@1.8,@1.6,@1.4,@1.2,@1.0];
   
//创建动画分组对象
   
CAAnimationGroup*group = [CAAnimationGroupanimation];
   
//将两组动画效果添加到分组动画中
    group.
duration = 8;
    group.
repeatCount= 1000;
   
    group.
animations= @[keyFramePath,keyFrameScale];
    [
self.balloon.layeraddAnimation:groupforKey:nil];
}






























0 0
原创粉丝点击