Permalink
Browse files

---

  • Loading branch information...
1 parent d4d9aba commit 16462f4e3e83b5493fe0fa2abe85a4cb4b7b87dc @YuriyBosov YuriyBosov committed Jan 30, 2012
Showing with 2,005 additions and 27 deletions.
  1. BIN .DS_Store
  2. 0 MUControls/{ → InputFields}/MUTextField.h
  3. 0 MUControls/{ → InputFields}/MUTextField.m
  4. +21 −0 MUControls/InputFields/MUTextFieldPadding.h
  5. +48 −0 MUControls/InputFields/MUTextFieldPadding.m
  6. 0 MUControls/{ → InputFields}/MUTextView.h
  7. 0 MUControls/{ → InputFields}/MUTextView.m
  8. 0 MUControls/{ → InputFields}/MUTextViewAutosize.h
  9. 0 MUControls/{ → InputFields}/MUTextViewAutosize.m
  10. +27 −0 MUControls/MUKeyboardAvoiding/MUKeyboardAvoidingScrollView.h
  11. +294 −0 MUControls/MUKeyboardAvoiding/MUKeyboardAvoidingScrollView.m
  12. +26 −0 MUControls/MUKeyboardAvoiding/MUKeyboardAvoidingTableView.h
  13. +304 −0 MUControls/MUKeyboardAvoiding/MUKeyboardAvoidingTableView.m
  14. +4 −7 MUControls/MUPopupControllers/MUPopupHoursMinutesPicker.m
  15. +1 −1 MUControls/MUTableViewCell2Half/MUTableViewCell2Half.h
  16. +1 −1 MUCore/MUTitledID.m
  17. +7 −1 MUCore/MUValidationGroup.h
  18. +30 −9 MUCore/MUValidationGroup.m
  19. +2 −0 MUCore/MUValidator.h
  20. +17 −8 MUCore/MUValidator.m
  21. +5 −0 README
  22. +37 −0 ThirdParty/DCRoundSwitch/DCRoundSwitch.h
  23. +431 −0 ThirdParty/DCRoundSwitch/DCRoundSwitch.m
  24. +18 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchKnobLayer.h
  25. +69 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchKnobLayer.m
  26. +16 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchOutlineLayer.h
  27. +66 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchOutlineLayer.m
  28. +26 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchToggleLayer.h
  29. +102 −0 ThirdParty/DCRoundSwitch/DCRoundSwitchToggleLayer.m
  30. +19 −0 ThirdParty/DCRoundSwitch/license.txt
  31. +39 −0 ThirdParty/DCRoundSwitch/readme.md
  32. +71 −0 ThirdParty/DateExtentions/NSDate-Utilities.h
  33. +324 −0 ThirdParty/DateExtentions/NSDate-Utilities.m
View
BIN .DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,21 @@
+//
+// MUTextField.h
+// ROM
+//
+// Created by Malaar on 7/8/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MUTextField.h"
+
+@interface MUTextFieldPadding : MUTextField
+{
+}
+
++ (id) textFieldPaddingWithBG:(UIImage*)aBG padding:(int)aPadding;
+- (id) initWithBG:(UIImage*)aBG padding:(int)aPadding;
+
+- (void) setPadding:(int)aPadding;
+
+@end
@@ -0,0 +1,48 @@
+//
+// MUTextField.m
+// ROM
+//
+// Created by Malaar on 7/8/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "MUTextFieldPadding.h"
+
+
+@implementation MUTextFieldPadding
+
+#pragma mark - init/dealloc
+//==========================================================================================
++ (id) textFieldPaddingWithBG:(UIImage*)aBG padding:(int)aPadding;
+{
+ return [[[MUTextFieldPadding alloc] initWithBG:aBG padding:aPadding] autorelease];
+}
+
+//==========================================================================================
+- (id) initWithBG:(UIImage*)aBG padding:(int)aPadding
+{
+ self = [super initWithFrame: CGRectMake(0, 0, aBG.size.width, aBG.size.width)];
+ if(self)
+ {
+ self.background = [aBG stretchableImageWithLeftCapWidth:aBG.size.width/2 topCapHeight:aBG.size.height/2];
+ self.borderStyle = UITextBorderStyleNone;
+ [self setPadding:aPadding];
+ }
+
+ return self;
+}
+
+#pragma mark - customization
+//==========================================================================================
+- (void) setPadding:(int)aPadding
+{
+ UIView* view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, aPadding, self.bounds.size.height)] autorelease];
+ self.leftView = view;
+ self.leftViewMode = UITextFieldViewModeAlways;
+}
+
+
+//==========================================================================================
+//==========================================================================================
+//==========================================================================================
+@end
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,27 @@
+//
+// MUKeyboardAvoidingScrollView.h
+// MUKit
+//
+// Created by Yuriy Bosov on 1/30/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+// Taken as a basis for an example of "TPKeyboardAvoidingScrollView"(Created by Michael Tyson)
+
+#import <UIKit/UIKit.h>
+
+@interface MUKeyboardAvoidingScrollView : UIScrollView
+{
+ UIEdgeInsets _priorInset;
+ BOOL _keyboardVisible;
+ CGRect _keyboardRect;
+ CGSize _originalContentSize;
+ NSMutableArray *_objectsInKeyboard;
+}
+
+- (void)adjustOffset;
+- (void)hideKeyBoard;
+- (void)addObjectForKeyboard:(id<UITextInputTraits>)objectForKeyboard;
+- (void)addObjectsForKeyboard:(NSArray *)objectsForKeyboard;
+- (void)responderShouldReturn:(UIResponder*)aResponder;
+
+@end
@@ -0,0 +1,294 @@
+//
+// MUKeyboardAvoidingScrollView.m
+// MUKit
+//
+// Created by Yuriy Bosov on 1/30/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "MUKeyboardAvoidingScrollView.h"
+
+#define _UIKeyboardFrameEndUserInfoKey (&UIKeyboardFrameEndUserInfoKey != NULL ? UIKeyboardFrameEndUserInfoKey : @"UIKeyboardBoundsUserInfoKey")
+
+//==============================================================================
+@interface MUKeyboardAvoidingScrollView (Init)
+
+- (void)setup;
+
+@end
+
+//==============================================================================
+//==============================================================================
+//==============================================================================
+@interface MUKeyboardAvoidingScrollView (Private)
+
+- (UIView*)findFirstResponderBeneathView:(UIView*)view;
+- (UIEdgeInsets)contentInsetForKeyboard;
+- (CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space;
+- (CGRect)keyboardRect;
+
+@end
+
+//==============================================================================
+//==============================================================================
+//==============================================================================
+@implementation MUKeyboardAvoidingScrollView
+
+#pragma mark - Init/Dealloc
+//==============================================================================
+-(id)initWithFrame:(CGRect)frame
+{
+ if ( !(self = [super initWithFrame:frame]) )
+ {
+ [self setup];
+ }
+ return self;
+}
+
+//==============================================================================
+-(void)awakeFromNib
+{
+ [super awakeFromNib];
+ [self setup];
+}
+
+//==============================================================================
+- (void)setup
+{
+ if ( CGSizeEqualToSize(self.contentSize, CGSizeZero) )
+ self.contentSize = self.bounds.size;
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
+
+ _objectsInKeyboard = [NSMutableArray new];
+}
+
+//==============================================================================
+-(void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [_objectsInKeyboard release];
+ [super dealloc];
+}
+
+#pragma mark - SetFrame/SetContentSize/TouchesEnded
+//==============================================================================
+-(void)setFrame:(CGRect)frame
+{
+ [super setFrame:frame];
+
+ CGSize contentSize = _originalContentSize;
+ contentSize.width = MAX(contentSize.width, self.frame.size.width);
+ contentSize.height = MAX(contentSize.height, self.frame.size.height);
+ [super setContentSize:contentSize];
+
+ if ( _keyboardVisible )
+ {
+ self.contentInset = [self contentInsetForKeyboard];
+ }
+}
+
+//==============================================================================
+-(void)setContentSize:(CGSize)contentSize
+{
+ _originalContentSize = contentSize;
+
+ contentSize.width = MAX(contentSize.width, self.frame.size.width);
+ contentSize.height = MAX(contentSize.height, self.frame.size.height);
+ [super setContentSize:contentSize];
+
+ if ( _keyboardVisible )
+ {
+ self.contentInset = [self contentInsetForKeyboard];
+ }
+}
+
+//==============================================================================
+- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self hideKeyBoard];
+ [super touchesEnded:touches withEvent:event];
+}
+
+#pragma mark - NSNotification
+//==============================================================================
+- (void)keyboardWillShow:(NSNotification*)notification
+{
+ _keyboardRect = [[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue];
+ _keyboardVisible = YES;
+
+ UIView *firstResponder = [self findFirstResponderBeneathView:self];
+ if ( !firstResponder )
+ {
+ // No child view is the first responder - nothing to do here
+ return;
+ }
+
+ _priorInset = self.contentInset;
+
+ // Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
+ [UIView beginAnimations:nil context:NULL];
+ [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
+ [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
+
+ self.contentInset = [self contentInsetForKeyboard];
+ [self setContentOffset:CGPointMake(self.contentOffset.x,
+ [self idealOffsetForView:firstResponder withSpace:[self keyboardRect].origin.y - self.bounds.origin.y])
+ animated:YES];
+
+ [UIView commitAnimations];
+}
+
+//==============================================================================
+- (void)keyboardWillHide:(NSNotification*)notification
+{
+ _keyboardRect = CGRectZero;
+ _keyboardVisible = NO;
+
+ // Restore dimensions to prior size
+ [UIView beginAnimations:nil context:NULL];
+ [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
+ [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
+ self.contentInset = _priorInset;
+ [UIView commitAnimations];
+}
+
+//==============================================================================
+- (void)keyboardDidHide:(NSNotification*)notification
+{
+ if (self.contentOffset.y > 0 && self.frame.size.height > self.contentSize.height - 20)
+ self.contentOffset = CGPointZero;
+}
+
+#pragma mark - Private Methods
+//==============================================================================
+- (UIView*)findFirstResponderBeneathView:(UIView*)view
+{
+ // Search recursively for first responder
+ for ( UIView *childView in view.subviews )
+ {
+ if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] )
+ return childView;
+ UIView *result = [self findFirstResponderBeneathView:childView];
+ if ( result )
+ return result;
+ }
+ return nil;
+}
+
+//==============================================================================
+- (UIEdgeInsets)contentInsetForKeyboard {
+ UIEdgeInsets newInset = self.contentInset;
+ CGRect keyboardRect = [self keyboardRect];
+ newInset.bottom = keyboardRect.size.height - ((keyboardRect.origin.y+keyboardRect.size.height) - (self.bounds.origin.y+self.bounds.size.height));
+ return newInset;
+}
+
+//==============================================================================
+-(CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space
+{
+ // Convert the rect to get the view's distance from the top of the scrollView.
+ CGRect rect = [view convertRect:view.bounds toView:self];
+
+ // Set starting offset to that point
+ CGFloat offset = rect.origin.y;
+
+ if ( self.contentSize.height - offset < space )
+ {
+ // Scroll to the bottom
+ offset = self.contentSize.height - space;
+ }
+ else
+ {
+ if ( view.bounds.size.height < space )
+ {
+ // Center vertically if there's room
+ offset -= floor((space-view.bounds.size.height)/2.0);
+ }
+ if ( offset + space > self.contentSize.height )
+ {
+ // Clamp to content size
+ offset = self.contentSize.height - space;
+ }
+ }
+
+ if (offset < 0) offset = 0;
+
+ return offset;
+}
+
+//==============================================================================
+- (CGRect)keyboardRect
+{
+ CGRect keyboardRect = [self convertRect:_keyboardRect fromView:nil];
+ if ( keyboardRect.origin.y == 0 )
+ {
+ CGRect screenBounds = [self convertRect:[UIScreen mainScreen].bounds fromView:nil];
+ keyboardRect.origin = CGPointMake(0, screenBounds.size.height - keyboardRect.size.height);
+ }
+ return keyboardRect;
+}
+
+#pragma mark - Public Methods
+//==============================================================================
+-(void)adjustOffset
+{
+ // Only do this if the keyboard is already visible
+ if ( !_keyboardVisible ) return;
+
+ CGFloat visibleSpace = self.bounds.size.height - self.contentInset.top - self.contentInset.bottom;
+
+ CGPoint idealOffset = CGPointMake(0, [self idealOffsetForView:[self findFirstResponderBeneathView:self] withSpace:visibleSpace]);
+
+ [self setContentOffset:idealOffset animated:YES];
+}
+
+//==============================================================================
+- (void)hideKeyBoard
+{
+ [[self findFirstResponderBeneathView:self] resignFirstResponder];
+}
+
+//==============================================================================
+- (void)addObjectForKeyboard:(id<UITextInputTraits>)objectForKeyboard
+{
+ if ([_objectsInKeyboard count] > 0)
+ {
+ [[_objectsInKeyboard lastObject] setReturnKeyType:UIReturnKeyNext];
+ }
+
+ [objectForKeyboard setReturnKeyType:UIReturnKeyDone];
+ [_objectsInKeyboard addObject:objectForKeyboard];
+}
+
+//==============================================================================
+- (void)addObjectsForKeyboard:(NSArray *)objectsForKeyboard
+{
+ for (id obj in objectsForKeyboard)
+ {
+ if ([obj conformsToProtocol:@protocol(UITextInputTraits)])
+ {
+ [self addObjectForKeyboard:obj];
+ }
+ else
+ {
+ NSAssert(nil, @"MUKit(MUKeyboardAvoidingScrollView): object does not implement the protocol 'UITextInputTraits'");
+ }
+ }
+}
+
+//==============================================================================
+- (void)responderShouldReturn:(UIResponder*)aResponder
+{
+ BOOL findResponder = [_objectsInKeyboard containsObject:aResponder];
+ NSInteger index = [_objectsInKeyboard indexOfObject:aResponder];
+ if (findResponder && index >= 0 && index < [_objectsInKeyboard count] - 1) {
+ [[_objectsInKeyboard objectAtIndex:index + 1] becomeFirstResponder];
+ } else{
+ [aResponder resignFirstResponder];
+ }
+}
+
+@end
Oops, something went wrong.

0 comments on commit 16462f4

Please sign in to comment.