• CGPathAddArc


     

    使用CGPathAddArc使UIView的Layer绕中心点旋转

     775人阅读 评论(0) 收藏 举报
    [plain] view plaincopy
    1. float angle = 360 / 6;  
    2. for (int i = 0; i < 6; i++) {  
    3.     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    4.     float offsetAngle = angle * i;  
    5.     button.bounds = CGRectMake(0, 0, 32, 32);  
    6.     button.center = CGPointMake(cos(offsetAngle * RADIANS) * 160, sin(offsetAngle * RADIANS) * 160);  
    7.     button.tag = i;  
    8.     CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];  
    9.     CGMutablePathRef path = CGPathCreateMutable();  
    10.     pathAnimation.calculationMode = kCAAnimationPaced;  
    11.     pathAnimation.fillMode = kCAFillModeForwards;  
    12.     pathAnimation.removedOnCompletion = NO;  
    13.     pathAnimation.duration = 2;  
    14.     CGPathMoveToPoint(path, NULL, button.center.x, button.center.y);  
    15.     CGPathAddArc(path, NULL, 0, 0, 160, offsetAngle * M_PI/180, offsetAngle * M_PI/180 + M_PI, YES);  
    16.     pathAnimation.path = path;  
    17.     CGPathRelease(path);  
    18.     [button.layer addAnimation:pathAnimation forKey:@"curve"];  
    19.     [tabBarView addSubview:button];  
    20. }  

    因为只是Layer的内容发生的位置变化,其实UIView还是在原来的位置上,如果需要使用应该在Animation结束后重新设定UIView的位置.

    顺便翻译一下原文:

     

    CGPathAddArc (

       CGMutablePathRef path,

       const CGAffineTransform *m,

       CGFloat x,

       CGFloat y,

       CGFloat radius,

       CGFloat startAngle,

       CGFloat endAngle,

       bool clockwise

    );

    path:动画的路径;

    m:layer的transform;

    x:其实x和y是什么我还没弄明白,根据原文应该是弧的圆心点,但我设置过,这更像是偏移量;

    y:同上;

    startAngle:起始的角度点,零度是与x轴相交点,度数为顺时针;

    endAngle:结束的角度点;

    clockwis:是否顺时针.

  • 相关阅读:
    android intent 传递list或者对象
    MyEclipse快捷键大全
    keystore 介绍
    oracle存储过程学习---包的概念
    判断变量类型
    Android自定义控件之TextView
    Myeclipse SVN 修改用户名和密码
    关于Inflater
    windowsxp系统下SVN添加新用户
    【原创】python:open函数的使用方法
  • 原文地址:https://www.cnblogs.com/yulang314/p/3720628.html
Copyright © 2020-2023  润新知