-
Notifications
You must be signed in to change notification settings - Fork 2
/
Utils.m
executable file
·65 lines (56 loc) · 2.18 KB
/
Utils.m
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
57
58
59
60
61
62
63
64
65
//
// Utils.m
// IndoorMapScene
//
// Created by apple on 13-10-29.
// Copyright (c) 2013年 apple. All rights reserved.
//
#import "Utils.h"
@implementation Utils
//************************贝塞尔路径***************************//
+ (UIBezierPath *)bezierPathFromCoordinateString:(NSString *)strCoordinate
{
UIBezierPath *path = [UIBezierPath new];
NSArray *data = [strCoordinate componentsSeparatedByString:@","];
NSUInteger countTotal = [data count];
NSUInteger countCoord = countTotal/2;
for(NSUInteger i = 0; i < countCoord; i++)
{
NSUInteger index = i<<1;
CGPoint aPoint = CGPointMake([[data objectAtIndex:index] floatValue],
[[data objectAtIndex:index+1] floatValue]);
if(i == 0)
{
[path moveToPoint:aPoint];
}
[path addLineToPoint:aPoint];
}
[path closePath];
return path;
}
//************************路径结构体定义************************//
+ (NSString *)pathStringWithFrame:(CGRect)rect
{
NSMutableString *result = [[NSMutableString alloc] init];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.x]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.y]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.x + rect.size.width]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.y]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.x + rect.size.width]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.y + rect.size.height]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.x]];
[result appendString:@","];
[result appendString:[NSString stringWithFormat:@"%f", rect.origin.y + rect.size.height]];
return result;
}
+ (CGPoint)gravityPointInRect:(CGRect)rect
{
return CGPointMake(rect.origin.x + rect.size.width/2.0f, rect.origin.y + rect.size.height/2.0f);
}
@end