美文网首页iOS开发
iOS - 围绕某个点做往复旋转动画

iOS - 围绕某个点做往复旋转动画

作者: 想飞的菜鸟 | 来源:发表于2020-09-27 16:36 被阅读0次
    CGPoint oldOrigin = self.bellImgV.frame.origin;
    // 围绕旋转的点
    self.bellImgV.layer.anchorPoint = CGPointMake(0.3, 0);
    CGPoint newOrigin = self.bellImgV.frame.origin;
    CGPoint transition;
    transition.x = newOrigin.x - oldOrigin.x;
    transition.y = newOrigin.y - oldOrigin.y;
    self.bellImgV.center = CGPointMake (self.bellImgV.center.x - transition.x, self.bellImgV.center.y - transition.y);
    
    [self.bellImgV.layer removeAllAnimations];
    CABasicAnimation *rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    // 旋转角度
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI*0.15];
    rotationAnimation.duration = 1;
    rotationAnimation.repeatCount = HUGE_VALF;
    // 动画结束时是否执行逆动画
    rotationAnimation.autoreverses = YES;
    [self.bellImgV.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

    相关文章

      网友评论

        本文标题:iOS - 围绕某个点做往复旋转动画

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