-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIView+Common.m
108 lines (89 loc) · 1.73 KB
/
UIView+Common.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#import "UIView+Common.h"
@implementation UIView (Common)
@end
@implementation UIView (Postion)
/**
* 获取屏幕宽度
*
* @return 屏幕宽度
*/
CGFloat screenWidth() {
return [[UIScreen mainScreen] bounds].size.width;
}
/**
* 获取屏幕高度
*
* @return 屏幕高度
*/
CGFloat screenHeight() {
return [[UIScreen mainScreen] bounds].size.height;
}
/**
* 根据 frame 返回宽高
*
* @param rect 视图的 frame
*
* @return frame 的宽高
*/
CGFloat width(CGRect rect) {
return rect.size.width;
}
CGFloat height(CGRect rect) {
return rect.size.height;
}
/**
* 返回当前视图的宽
*
* @return 视图的宽
*/
- (CGFloat)getWidth {
return self.frame.size.width;
}
/**
* 返回当前视图的高
*
* @return 视图的高
*/
- (CGFloat)getHeight {
return self.frame.size.height;
}
/**
* 返回当前视图的点坐标
*
* @param view 当前视图
*
* @return 视图的点坐标
*/
CGFloat maxX(UIView *view) {
return CGRectGetMaxX(view.frame);
}
CGFloat minX(UIView *view) {
return CGRectGetMinX(view.frame);
}
CGFloat midX(UIView *view) {
return CGRectGetMidX(view.frame);
}
CGFloat maxY(UIView *view) {
return CGRectGetMaxY(view.frame);
}
CGFloat minY(UIView *view) {
return CGRectGetMinY(view.frame);
}
CGFloat midY(UIView *view) {
return CGRectGetMidY(view.frame);
}
/**
* 获取子视图的父视图
*
* @return
*/
- (UIViewController*)myViewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)nextResponder;
}
}
return nil;
}
@end