首页 > 系统 > iOS > 正文

iOS 动画(1)

2019-11-07 23:46:46
字体:
来源:转载
供稿:网友

设置UIImageView

_imageAime = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)];

_imageAime.image =[UIImage imageNamed:@"icon_baiban"];

[self.view addSubview:_imageAime];

//缩放效果

-(void)Zoom{

  [UIView animateWithDuration:3 animations:^{        //动画的逻辑    _imageAime.frame =CGRectMake(10, 200, 300, 250);    } completion:^(BOOL finished) {        //动画结束之后要执行的代码        //重开了一个UIView动画,还原位置        [UIView animateWithDuration:3 animations:^{            _imageAime.frame =CGRectMake(50, 100, 100, 100);        }];    }];

}

//旋转效果

-(void)rotation{

    CABasicAnimation *basianimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

     //设置时长

    [basianimation setDuration:10];

    //重复次数

    [basianimation setRepeatCount:2];

   //所改变属性的起始值

    basianimation.fromValue = [NSNumber numberWithDouble:2];

    //所改变属性的结束时的值

    basianimation.toValue = [NSNumber numberWithDouble:M_PI * 20];    [_imageAime.layer addAnimation:basianimation forKey:nil];

    //动画结束时是否执行逆动画

    basianimation.autoreverses = YES;

}

//虚化效果

-(void)grammaticalization{

  //第三种UIView动画的另一种写法(没有block)    [UIView beginAnimations:@"view动画的另一种写法" context:nil];    //设置时长    [UIView setAnimationDuration:1];    //设置重复次数    [UIView setAnimationRepeatCount:NSIntegerMax];    //动画的逻辑    _imageAime.alpha =0.4;    //结束动画    [UIView commitAnimations];

}

//

-(void)tremble{

 //2,延时时间(等待)3,颤抖效果,值越小,抖动的越厉害 4,开始时的动画速度,值越大速度越快    [UIView animateWithDuration:2 delay:1 usingSPRingWithDamping:0.2 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseInOut animations:^{        _imageAime.frame =CGRectMake(100, 400, 300, 250);    } completion:^(BOOL finished) {            }];

}

-(void)curve{

    //关键帧动画    CAKeyframeAnimation *keyanimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];    //创建一个路径, 用来记录每一帧    CGMutablePathRef path = CGPathCreateMutable();    //指定移动的起点    CGPathMoveToPoint(path, NULL, _imageAime.center.x, _imageAime.center.y);    //画一条曲线(贝塞尔曲线)    CGPathAddCurveToPoint(path, NULL, 100, 100, 370, 320, 100, 690);        //设置路径    [keyanimation setPath:path];    //设置时间    [keyanimation setDuration:3];    //设置重复次数    [keyanimation setRepeatCount:1];        [_imageAime.layer addAnimation:keyanimation forKey:@"keyanimation"     ];

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表