ios无限旋转

本文详细解析了如何使用Core Animation框架在iOS应用中实现图片无线旋转动画,包括关键属性设置、循环重复机制及代码实现,旨在帮助开发者理解和实践动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在开发过程中,我们有时需要实现图片无线旋转动画,下面给出示例代码:

    CABasicAnimation* rotationAnimation;

    rotationAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = [NSNumbernumberWithFloat: M_PI *2.0 ];

    rotationAnimation.duration =1;

    rotationAnimation.cumulative =YES;

    rotationAnimation.repeatCount =HUGE_VALF;

    

    [_imageView .layeraddAnimation:rotationAnimation forKey:@"rotationAnimation"];


对repeatCount做个说明,官方文档是这么说的

May be fractional. If the repeatCount is 0, it is ignored. Defaults to 0. If both repeatDuration and repeatCount are specified the behavior is undefined.

Setting this property to HUGE_VALF will cause the animation to repeat forever.


有的会使用下面方法实现

    rotation = rotation + 2*M_PI;

   [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform t = CGAffineTransformMakeRotation(rotation);

        self.imageView.transform = t;

    } completion:^(BOOL finished) {

        [self useTouchIdButtonCLicked:nil];

   }];

上述代码可以实现循环,但是中间会停顿一下,想必不是自己想要的效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值