美文网首页
ios 表针的旋转

ios 表针的旋转

作者: 40dd4b561abe | 来源:发表于2017-08-23 11:04 被阅读2次

首先声明一个全局变量 CGFloat tmp;
第一个180;是能旋转多大角;

/*
 * pointToAngle 按角度旋转
 * @angel CGFloat 角度的比例(1—0)
 * @duration CGFloat 动画执行时间
 */
- (void) pointToAngle:(CGFloat) angle Duration:(CGFloat) duration
{
    CAKeyframeAnimation * ani = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    ani.duration = duration;
    ani.removedOnCompletion = NO;
    ani.fillMode = kCAFillModeForwards;
    ani.autoreverses = NO;
    
    NSMutableArray * arr = [NSMutableArray array];
    
    CGFloat dd = (angle - tmp) /10;
    for (int i = 0 ; i<11; i++) {
        [arr addObject:[NSValue valueWithCATransform3D:CATransform3DRotate(CATransform3DIdentity, (i * dd + tmp) * 180 *M_PI/180, 0, 0, 1)]];
    }
    ani.values = arr;
    ani.delegate = self;
    [self.shizhi.layer addAnimation:ani forKey:@"PostionKeyframeValueAni"];
    tmp = angle;

}

相关文章

网友评论

      本文标题:ios 表针的旋转

      本文链接:https://www.haomeiwen.com/subject/ttrddxtx.html