zoukankan      html  css  js  c++  java
  • iOS环形控制器、环形按钮

    这两天接手了一个外包的UI,有一个环形的控制器,需求改啊改的:“安卓已经实现了……”,最讨厌这句了,最后做了一版,对方终于满意了,删掉其他的繁琐部分,留下控制器部分,大家看看,有更好的想法欢迎分享。

    惯例,先上图

    源码在这里

    给大家做个分析吧:

    核心代码解析:

     1 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
     2 {
     3     UITouch *touch = [touches anyObject];
     4     CGPoint point = [touch locationInView:self.image];//取点
     5     
     6     CGPoint pointerposition = [self getPoint:point];//加工点
     7     double radian = [self getradian:pointerposition];//求弧度
     8     if (radian>-0.81&&radian<3.99) {//根据弧度范围处理点的运动
     9         _pointer.transform = CGAffineTransformMakeRotation(- (radian - M_PI_2));
    10         _pointer.center = pointerposition;
    11     }
    12 }
    13 
    14 - (double)getradian:(CGPoint)point//利用点求弧度
    15 {
    16     point.x -= _center.x;
    17     point.y -= _center.y;
    18     double cosp = point.x / _radius;//求余弦
    19     double radian = acos(cosp);//转弧度
    20     radian = (radian < M_PI_2 && point.y > 0) ? - radian : radian;//判断象限,注意屏幕坐标系的方向
    21     radian = (radian > M_PI_2 && point.y > 0) ? M_PI * 2 - radian : radian;
    22     return radian;
    23 }
    24 
    25 - (CGPoint) getPoint:(CGPoint)point//将触摸点,转换成圆周上的点
    26 {
    27     point.x -= _center.x;
    28     point.y -= _center.y;//以上两步为了将左边系的原点固定到圆心,
    29     double r = sqrt(point.x * point.x + point.y * point.y) / _radius;
    30     point.x /= r;
    31     point.y /= r;
    32     point.x += _center.x;
    33     point.y += _center.y;//按照比例求出对应的圆上的点
    34     return point;
    35 }
    View Code
  • 相关阅读:
    Codeforces Round #594 (Div. 2) ABC题
    Codeforces Round #596 (Div. 2) ABCD题
    数据结构实验5——二叉树
    数据结构实验4——字符串匹配
    数据结构实验3——用栈求解算术表达式
    友链
    Codeforces Round #577 (Div. 2)
    Educational Codeforces Round 70 (Rated for Div. 2)
    Codeforces Round #578 (Div. 2)
    2020 Multi-University Training Contest 10(待补
  • 原文地址:https://www.cnblogs.com/kongkaikai/p/4966599.html
Copyright © 2011-2022 走看看