-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathP34Utils.m
107 lines (95 loc) · 2.66 KB
/
P34Utils.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
#import "P34Utils.h"
void doAfter(CGFloat delay, BasicBlock action)
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_main_queue(), action);
}
void doSyncOnMain(BasicBlock action)
{
if ([NSThread isMainThread])
action();
else
dispatch_sync(dispatch_get_main_queue(), action);
}
BOOL isIphone5OrLarger()
{
static NSInteger isIphone5 = -1;
if (isIphone5 < 0)
{
doSyncOnMain(^{
if (SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"7.0"))
{
isIphone5 = [[UIScreen mainScreen] bounds].size.height >= 568;
}
else
{
isIphone5 = ((!UIApplication.landscape && [[UIScreen mainScreen] bounds].size.height >= 568)
|| (UIApplication.landscape && [[UIScreen mainScreen] bounds].size.width >= 568));
}
});
}
return isIphone5 > 0;
}
BOOL isIphone5()
{
static NSInteger isIphone5 = -1;
if (isIphone5 < 0)
{
doSyncOnMain(^{
if (SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"7.0"))
{
isIphone5 = [[UIScreen mainScreen] bounds].size.height == 568;
}
else
{
isIphone5 = ((!UIApplication.landscape && [[UIScreen mainScreen] bounds].size.height == 568)
|| (UIApplication.landscape && [[UIScreen mainScreen] bounds].size.width == 568));
}
});
}
return isIphone5 > 0;
}
BOOL isIphone6()
{
static NSInteger isIphone6 = -1;
if (isIphone6 < 0)
{
doSyncOnMain(^{
isIphone6 = ((!UIApplication.landscape && [[UIScreen mainScreen] bounds].size.height == 667)
|| (UIApplication.landscape && [[UIScreen mainScreen] bounds].size.width == 667));
});
}
return isIphone6 > 0;
}
BOOL isIphone6Plus()
{
static NSInteger isIphone6Plus = -1;
if (isIphone6Plus < 0)
{
doSyncOnMain(^{
isIphone6Plus = ((!UIApplication.landscape && [[UIScreen mainScreen] bounds].size.height == 736)
|| (UIApplication.landscape && [[UIScreen mainScreen] bounds].size.width == 736));
});
}
return isIphone6Plus > 0;
}
BOOL isIpad()
{
static NSInteger isiPad = -1;
if (isiPad < 0)
{
doSyncOnMain(^{
isiPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
});
}
return isiPad > 0;
}
BOOL isRetina()
{
static NSInteger isRetina = -1;
if (isRetina < 0)
{ doSyncOnMain(^{
isRetina = UIScreen.mainScreen.scale > 1;
});
}
return isRetina > 0;
}