This repository has been archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRFUIInterfaceOrientationSupport.h
116 lines (97 loc) · 3.86 KB
/
RFUIInterfaceOrientationSupport.h
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
109
110
111
112
113
114
115
116
/*!
RFUIInterfaceOrientationSupport
RFUI
Copyright (c) 2012-2013 BB9z
https://github.com/RFUI/Core
The MIT License (MIT)
http://www.opensource.org/licenses/mit-license.php
*/
#ifndef _RFUIInterfaceOrientationSupport_
#define _RFUIInterfaceOrientationSupport_
// Tools
#define _RFUIInterfaceOrientationSupport_ShouldAutorotate \
- (BOOL)shouldAutorotate {\
return YES;\
}
#define _RFUIInterfaceOrientationSupport_SupportedInterfaceOrientations(iPhoneOption, iPadOption) \
- (NSUInteger)supportedInterfaceOrientations {\
if ([UIDevice currentDevice].isPad) {\
return iPadOption;\
}\
else {\
return iPhoneOption;\
}\
}
#define _RFUIInterfaceOrientationSupport_SupportedInterfaceOrientationsBoth(Option) \
- (NSUInteger)supportedInterfaceOrientations {\
return Option;\
}
#pragma mark - Rule
// iPhone Only Portrait, no upside down
// iPad All
#define RFUIInterfaceOrientationSupportDefault \
_RFUIInterfaceOrientationSupport_ShouldAutorotate\
_RFUIInterfaceOrientationSupport_SupportedInterfaceOrientations(UIInterfaceOrientationMaskPortrait, UIInterfaceOrientationMaskAll)\
\
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {\
if ([UIDevice currentDevice].isPad) {\
return YES;\
}\
else {\
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);\
}\
}
// iPhone Only Portrait, no upside down
// iPad Portrait + PortraitUpsideDown
#define RFUIInterfaceOrientationSupportPortrait \
_RFUIInterfaceOrientationSupport_ShouldAutorotate\
_RFUIInterfaceOrientationSupport_SupportedInterfaceOrientations(UIInterfaceOrientationMaskPortrait, (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))\
\
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {\
if ([UIDevice currentDevice].isPad) {\
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);\
}\
else {\
return (UIInterfaceOrientationPortrait == toInterfaceOrientation);\
}\
}
// iPhone & iPad Only Landscape (Left+Right)
#define RFUIInterfaceOrientationSupportLandscape \
_RFUIInterfaceOrientationSupport_ShouldAutorotate\
_RFUIInterfaceOrientationSupport_SupportedInterfaceOrientationsBoth(UIInterfaceOrientationMaskLandscape)\
\
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {\
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);\
}
// All, except PortraitUpsideDown on iPhone
#define RFUIInterfaceOrientationSupportAll \
_RFUIInterfaceOrientationSupport_ShouldAutorotate\
_RFUIInterfaceOrientationSupport_SupportedInterfaceOrientations(UIInterfaceOrientationMaskAllButUpsideDown, UIInterfaceOrientationMaskAll)\
\
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {\
if ([UIDevice currentDevice].isPad) {\
return YES;\
}\
else {\
return (UIInterfaceOrientationPortraitUpsideDown != toInterfaceOrientation);\
}\
}
#pragma mark -
// Let navigation controller rotate according to current view controller
// May not fallback to topViewController on iOS 5.
#define RFUIInterfaceOrientationSupportNavigation \
- (BOOL)shouldAutorotate {\
return [self.topViewController shouldAutorotate];\
}\
\
- (NSUInteger)supportedInterfaceOrientations {\
return [self.topViewController supportedInterfaceOrientations];\
}
#pragma mark -
// For disable
#define _RFUIInterfaceOrientationSupportDefault
#define _RFUIInterfaceOrientationSupportPortrait
#define _RFUIInterfaceOrientationSupportLandscape
#define _RFUIInterfaceOrientationSupportAll
#define _RFUIInterfaceOrientationSupportNavigation
#endif