开发者社区> 问答> 正文

CABasicAnimation中的锚点

define PI 3.14159265

-(void)rotation
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue = [NSNumber numberWithFloat:0];
    animation.toValue   = [NSNumber numberWithFloat:-PI/4];
    animation.duration  = 1.0f;
    [view.layer addAnimation:animation forKey:nil];
}

这段代码可以让这个view逆时针旋转45度 但是以为这个view的中心点为中心旋转的,如果我想以这个view的左下角的点为中心旋转,应该是添加什么样的代码呢?

展开
收起
a123456678 2016-07-20 15:12:12 2081 0
1 条回答
写回答
取消 提交回答
  • 设置一下Anchor Points即可。

    下图中,上半部分的anchorPoint为(0.5, 0.5),即anchorPoint为layer的中心。下半部分的anchorPoint为(0.0, 0.0),即anchorPoint为layer的左上角。同理我们可知,anchorPoint如果为(1.0, 1.0)的化就代表右下角。(注意iOS与OS X坐标系的不同)
    screenshot

    2019-07-17 19:58:55
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载