美文网首页
环形手势移动处理方式

环形手势移动处理方式

作者: CodingTom | 来源:发表于2020-05-20 16:29 被阅读0次

    https://github.com/NieYinlong/RoundRotatePanel/blob/master/%E5%9C%86%E7%9B%98%E5%88%BB%E5%BA%A6%E5%B0%BA/View/RoundRotatePanel.m

    #import <UIKit/UIKit.h>
    
    @interface RoundRotatePanel : UIControl
    /**
     *  中心点的坐标值
     */
    @property (nonatomic, assign) CGPoint centerPoint;
    
    
    @property (nonatomic, assign) CGFloat changedRadian;
    
    /**
     *  将图层旋转radian弧度
     *  @param radian 旋转的弧度
     */
    - (void)rotateByRadian:(CGFloat)radian;
    
    
    @end
    
    
    - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
        
        CGPoint previousLocation = [touch previousLocationInView:self];
        CGPoint location = [touch locationInView:self];
        CGFloat previousRadian = [self radianToCenterPoint:self.centerPoint withPoint:previousLocation];
        CGFloat curRadian = [self radianToCenterPoint:self.centerPoint withPoint:location];
        CGFloat changedRadian = curRadian - previousRadian;
        
        
        
        self.changedRadian = changedRadian;// 记录
        [self rotateByRadian:changedRadian];
        
        [self sendActionsForControlEvents:UIControlEventValueChanged];
        return YES;
    }
    
    /**
     *  以ColorPanel的anchorPoint为坐标原点建立坐标系,计算坐标点|point|与坐标原点的连线距离x轴正方向的夹角
     *  @param centerPoint 坐标原点坐标
     *  @param point       某坐标点
     *
     *  @return 坐标点|point|与坐标原点的连线距离x轴正方向的夹角
     */
    - (CGFloat)radianToCenterPoint:(CGPoint)centerPoint withPoint:(CGPoint)point {
        CGVector vector = CGVectorMake(point.x - centerPoint.x, point.y - centerPoint.y);
        return atan2f(vector.dy, vector.dx);
    }
    
    /**
     *  将图层旋转radian弧度
     *  @param radian 旋转的弧度
     */
    - (void)rotateByRadian:(CGFloat)radian {
        
        CGAffineTransform transform = self.layer.affineTransform;
        transform = CGAffineTransformRotate(transform, radian);
        self.layer.affineTransform = transform;
    }
    

    相关文章

      网友评论

          本文标题:环形手势移动处理方式

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