分享

CABasicAnimation中的锚点

 没原创_去搜索 2016-01-13
http://segmentfault.com/q/1010000000199286


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的左下角的点为中心旋转,应该是添加什么样的代码呢? 

1 个回答

3
采纳
xhinking 1.7k 2013年05月12日 回答 · 2013年05月12日 更新

设置一下Anchor Points即可。

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

下面这张图更清晰的解释了Anchor Points对layer的transformations变化的影响:

对于iOS,可以总结anchorPoint值对应layer的位置如下图:

对于你的问题,只需要设置view.layer的anchorPoint为(0.0, 1.0)即可以左下角为中心旋转。

参考连接:Core Animation Programming Guide

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多