需求

来源:互联网 发布:快手数据 编辑:程序博客网 时间:2024/04/23 15:41
#define ITMEMARGIN 40.0f#define BigRadius  120.0f@interface CalculationCircularFirstViewController ()@end@implementation CalculationCircularFirstViewController- (void)viewDidLoad{    [super viewDidLoad];    [self.view setBackgroundColor:[UIColor whiteColor]];        UIButton * b1 = [UIButton buttonWithType:UIButtonTypeCustom];    [b1 setFrame:CGRectMake(0, 0, 40, 40)];    [b1 setBackgroundColor:[UIColor redColor]];    [b1.layer setMasksToBounds:YES];    [b1.layer setCornerRadius:20];    [b1 setTitle:@"1" forState:UIControlStateNormal];    [self.view addSubview:b1];        UIButton * b2 = [UIButton buttonWithType:UIButtonTypeCustom];    [b2 setFrame:CGRectMake(0, 0, 40, 40)];    [b2 setBackgroundColor:[UIColor greenColor]];    [b2.layer setMasksToBounds:YES];    [b2.layer setCornerRadius:20];    [b2 setTitle:@"2" forState:UIControlStateNormal];    [self.view addSubview:b2];        UIButton * b3 = [UIButton buttonWithType:UIButtonTypeCustom];    [b3 setFrame:CGRectMake(0, 0, 40, 40)];    [b3 setBackgroundColor:[UIColor blueColor]];    [b3.layer setMasksToBounds:YES];    [b3.layer setCornerRadius:20];    [b3 setTitle:@"3" forState:UIControlStateNormal];    [self.view addSubview:b3];        UIButton * b4 = [UIButton buttonWithType:UIButtonTypeCustom];    [b4 setFrame:CGRectMake(0, 0, 40, 40)];    [b4 setBackgroundColor:[UIColor yellowColor]];    [b4.layer setMasksToBounds:YES];    [b4.layer setCornerRadius:20];    [b4 setTitle:@"4" forState:UIControlStateNormal];    [self.view addSubview:b4];        UIButton * b5 = [UIButton buttonWithType:UIButtonTypeCustom];    [b5 setFrame:CGRectMake(0, 0, 40, 40)];    [b5 setBackgroundColor:[UIColor lightGrayColor]];    [b5.layer setMasksToBounds:YES];    [b5.layer setCornerRadius:20];    [b5 setTitle:@"5" forState:UIControlStateNormal];    [self.view addSubview:b5];        UIButton * b6 = [UIButton buttonWithType:UIButtonTypeCustom];    [b6 setFrame:CGRectMake(0, 0, 40, 40)];    [b6 setBackgroundColor:[UIColor purpleColor]];    [b6.layer setMasksToBounds:YES];    [b6.layer setCornerRadius:20];    [b6 setTitle:@"6" forState:UIControlStateNormal];    [self.view addSubview:b6];        UIButton * b7 = [UIButton buttonWithType:UIButtonTypeCustom];    [b7 setFrame:CGRectMake(0, 0, 40, 40)];    [b7 setBackgroundColor:[UIColor blackColor]];    [b7.layer setMasksToBounds:YES];    [b7.layer setCornerRadius:20];    [b7 setTitle:@"7" forState:UIControlStateNormal];    [self.view addSubview:b7];        /*     every 0 point :{182.17167854309082, 170.34563064575195}     every 1 point :{198.25180530548096, 103.36706042289734}     every 2 point :{156.31924629211426, 48.719482421875}     every 3 point :{87.461061477661133, 46.916365623474121}     every 4 point :{42.725930213928223, 99.29448127746582}     every 5 point :{55.278630256652832, 167.02280521392822}     every 6 point :{115.81312298774719, 199.89036083221436}     */        CGPoint point1 = [self itmePointIndex:1 count:7];    CGPoint point2 = [self itmePointIndex:2 count:7];    CGPoint point3 = [self itmePointIndex:3 count:7];    CGPoint point4 = [self itmePointIndex:4 count:7];    CGPoint point5 = [self itmePointIndex:5 count:7];    CGPoint point6 = [self itmePointIndex:6 count:7];    CGPoint point7 = [self itmePointIndex:7 count:7];        [b1 setCenter:point1];    [b2 setCenter:point2];    [b3 setCenter:point3];    [b4 setCenter:point4];    [b5 setCenter:point5];    [b6 setCenter:point6];    [b7 setCenter:point7];}- (CGPoint)itmePointIndex:(NSInteger)index count:(NSInteger)count{    /* 角度是关键 */    /* π/180 是1度角对应的弧度数,只要乘以度数,就可以得到弧度 */    CGFloat degree = (360 / count) * (M_PI / 180);        CGFloat radius = BigRadius - ITMEMARGIN;        CGFloat x,y = 0.0f;    y = cosf(degree * index);    x = sinf(degree * index);        NSLog(@"index x y:  :%ld %f %f", index, x, y);        CGPoint point = CGPointMake((x * radius)+radius ,                                    (y * radius)+radius );    return point;}@end



效果如下:



可以把正弦余弦输出来看看:


0 0
原创粉丝点击