8 #import "EnkiUtilities.h"
13 + (float) pixelsForRetina:(
float) pixels
15 if ([[UIScreen mainScreen] Enki_isRetina]) {
22 #pragma mark - numeric methods
24 +(BOOL) AlmostEqualRelative:(
float) A and:(
float)B;
26 float maxRelDiEnki = FLT_EPSILON;
29 float diEnki = fabs(A - B);
33 float largest = (B > A) ? B : A;
35 if (diEnki <= largest * maxRelDiEnki)
41 #pragma mark - Grouped TableCell methods
42 static UIColor *EnkiUtiltiesBackgroundCellColor;
45 + (UIColor *)defaultBackgroundColor:(UITableViewCell *)inCell
48 if (NULL == EnkiUtiltiesBackgroundCellColor) {
53 NSString *version = [[UIDevice currentDevice] systemVersion];
54 NSString *firstLetter = [version substringToIndex:1];
56 if ([firstLetter isEqual:
@"4"]) {
57 EnkiUtiltiesBackgroundCellColor = [UIColor whiteColor];
59 EnkiUtiltiesBackgroundCellColor = [UIColor colorWithRed:(0xF7/255.0)green:(0xF7/255.0) blue:(0xF7/255.0) alpha:1.0];
63 return EnkiUtiltiesBackgroundCellColor;
67 #pragma mark - keyboard methods
70 + (void)keyboardWasShown:(NSNotification*)aNotification
71 view:(UIViewController *) view
72 scrollView:(UIScrollView *)scrollView
73 activeField:(UIView *) activeField
74 activeCell:(UITableViewCell *) activeCell
76 NSDictionary* info = [aNotification userInfo];
77 CGRect rawKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
79 CGRect properlyRotatedCoords = [view.view.window convertRect:rawKeyboardRect toView:view.view.window.rootViewController.view];
81 CGSize kbSize = properlyRotatedCoords.size;
84 UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
85 scrollView.contentInset = contentInsets;
86 scrollView.scrollIndicatorInsets = contentInsets;
88 CGRect viewRect = view.view.frame;
90 if (nil != activeCell) {
93 viewRect.size.height -= kbSize.height;
95 CGPoint origin = activeCell.frame.origin;
96 origin.x += activeField.frame.origin.x;
97 origin.y += activeField.frame.origin.y;
98 origin.y -= scrollView.contentOffset.y;
100 if (!CGRectContainsPoint(viewRect, origin) ) {
101 CGFloat scrollAmount = activeCell.frame.origin.y + activeField.frame.origin.y - 30;
102 CGPoint scrollPoint = CGPointMake(0.0, scrollAmount);
104 [scrollView setContentOffset:scrollPoint animated:YES];
108 CGRect fieldRect = activeField.frame;
110 float distanceFromBottom = (viewRect.origin.y + viewRect.size.height) - (fieldRect.origin.y + fieldRect.size.height);
111 float jumpNeeded = kbSize.height - distanceFromBottom;
114 [scrollView setContentOffset:CGPointMake(0,jumpNeeded +30) animated:YES];