图片前后旋转(头像前后旋转)

最近看到了用户的头像可以前后旋转,还是蛮酷炫的就写了段实现方法, 给需要帮助的人吧。

// 头像动画
    [self rotate360WithDuration:2.0 repeatCount:1];
    _headImageView.animationDuration = 2.0;
    _headImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"profileFansV2"],
                                      [UIImage imageNamed:@"profileCartListV2"],[UIImage imageNamed:@"profileCartListV2"],
                                      [UIImage imageNamed:@"profileCartListV2"],[UIImage imageNamed:@"profileCartListV2"],
                                      [UIImage imageNamed:@"profileFansV2"], nil];
    _headImageView.animationRepeatCount = 1;
    [_headImageView startAnimating];


- (void)rotate360WithDuration:(CGFloat)aDuration repeatCount:(CGFloat)aRepeatCount
{
    CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animation];
    theAnimation.values = [NSArray arrayWithObjects:
                           [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0,1,0)],
                           [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0,1,0)],
                           [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0,1,0)],
                           [NSValue valueWithCATransform3D:CATransform3DMakeRotation(2*M_PI, 0,1,0)],
                           nil];
    theAnimation.cumulative = YES;
    theAnimation.duration = aDuration;
    theAnimation.repeatCount = aRepeatCount;
    theAnimation.removedOnCompletion = YES;
   
    [_headImageView.layer addAnimation:theAnimation forKey:@"transform"];
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值