单军华
2018-07-12 3e8437ae559487362fae3525beb79c534c213a51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
//  JHPieForeBGView.m
//  JHCALayer
//
//  Created by cjatech-简豪 on 16/4/28.
//  Copyright © 2016年 JH. All rights reserved.
//
 
#import "JHPieForeBGView.h"
 
@implementation JHPieForeBGView
 
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self touchesBegan:touches withEvent:event];
}
 
 
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    UITouch *touch = [touches anyObject];
    
    CGPoint p = [touch locationInView:self];
    
    
    
    if ((p.x-self.frame.size.width/2)*(p.x-self.frame.size.width/2) + (p.y-self.frame.size.height/2)*(p.y-self.frame.size.height/2) >self.frame.size.height*self.frame.size.height) {
        return;
    }
    
    
    /* 计算角度并block回调 */
    CGFloat aLen2 = (p.x - self.frame.size.width/2)*(p.x - self.frame.size.width/2) + (p.y - self.frame.size.width/2)*(p.y - self.frame.size.width/2);
    CGFloat aLen = sqrt(aLen2);
    
    CGFloat cLen2 =self.frame.size.width/2 * self.frame.size.width/2;
    CGFloat cLen = self.frame.size.width/2;
    
    CGFloat bLen2 = (p.x - self.frame.size.width)*(p.x - self.frame.size.width) + (p.y - self.frame.size.width/2)*(p.y - self.frame.size.width/2);
 
    
    CGFloat angle = acos((aLen2 + cLen2 -bLen2)/2/aLen/cLen);
    
    if (p.y<self.frame.size.height/2) {
        angle = M_PI*2 -angle;
        
    }
    if (self.select) {
        self.select(angle,p);
    }
    
}
 
 
 
@end