This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
TTGlobalUICommon.m
184 lines (151 loc) · 5.77 KB
/
TTGlobalUICommon.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// Copyright 2009-2010 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "Three20UICommon/TTGlobalUICommon.h"
// UI
#import "Three20UICommon/UIWindowAdditions.h"
// Core
#import "Three20Core/TTGlobalCoreLocale.h"
const CGFloat ttkDefaultRowHeight = 44;
const CGFloat ttkDefaultPortraitToolbarHeight = 44;
const CGFloat ttkDefaultLandscapeToolbarHeight = 33;
const CGFloat ttkDefaultPortraitKeyboardHeight = 216;
const CGFloat ttkDefaultLandscapeKeyboardHeight = 160;
const CGFloat ttkGroupedTableCellInset = 10.0;
const CGFloat ttkDefaultTransitionDuration = 0.3;
const CGFloat ttkDefaultFastTransitionDuration = 0.2;
const CGFloat ttkDefaultFlipTransitionDuration = 0.7;
///////////////////////////////////////////////////////////////////////////////////////////////////
float TTOSVersion() {
return [[[UIDevice currentDevice] systemVersion] floatValue];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL TTOSVersionIsAtLeast(float version) {
// Floating-point comparison is pretty bad, so let's cut it some slack with an epsilon.
static const CGFloat kEpsilon = 0.0000001;
#ifdef __IPHONE_4_2
return 4.2 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_4_1
return 4.1 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_4_0
return 4.0 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_3_2
return 3.2 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_3_1
return 3.1 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_3_0
return 3.0 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_2_2
return 2.2 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_2_1
return 2.1 - version >= -kEpsilon;
#endif
#ifdef __IPHONE_2_0
return 2.0 - version >= -kEpsilon;
#endif
return NO;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL TTIsKeyboardVisible() {
// Operates on the assumption that the keyboard is visible if and only if there is a first
// responder; i.e. a control responding to key events
UIWindow* window = [UIApplication sharedApplication].keyWindow;
return !![window findFirstResponder];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL TTIsPhoneSupported() {
NSString* deviceType = [UIDevice currentDevice].model;
return [deviceType isEqualToString:@"iPhone"];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL TTIsPad() {
#ifdef __IPHONE_3_2
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
#else
return NO;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////
UIDeviceOrientation TTDeviceOrientation() {
UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationUnknown == orient) {
return UIDeviceOrientationPortrait;
} else {
return orient;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL TTIsSupportedOrientation(UIInterfaceOrientation orientation) {
if (TTIsPad()) {
return YES;
} else {
switch (orientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return YES;
default:
return NO;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CGAffineTransform TTRotateTransformForOrientation(UIInterfaceOrientation orientation) {
if (orientation == UIInterfaceOrientationLandscapeLeft) {
return CGAffineTransformMakeRotation(M_PI*1.5);
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
return CGAffineTransformMakeRotation(M_PI/2);
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
return CGAffineTransformMakeRotation(-M_PI);
} else {
return CGAffineTransformIdentity;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CGRect TTApplicationFrame() {
CGRect frame = [UIScreen mainScreen].applicationFrame;
return CGRectMake(0, 0, frame.size.width, frame.size.height);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CGFloat TTToolbarHeightForOrientation(UIInterfaceOrientation orientation) {
if (UIInterfaceOrientationIsPortrait(orientation)) {
return TT_ROW_HEIGHT;
} else {
return TT_LANDSCAPE_TOOLBAR_HEIGHT;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CGFloat TTKeyboardHeightForOrientation(UIInterfaceOrientation orientation) {
if (UIInterfaceOrientationIsPortrait(orientation)) {
return TT_KEYBOARD_HEIGHT;
} else {
return TT_LANDSCAPE_KEYBOARD_HEIGHT;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void TTAlert(NSString* message) {
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:TTLocalizedString(@"Alert", @"")
message:message delegate:nil
cancelButtonTitle:TTLocalizedString(@"OK", @"")
otherButtonTitles:nil] autorelease];
[alert show];
}