diff --git a/UIInputToolbarSample.xcodeproj/project.pbxproj b/UIInputToolbarSample.xcodeproj/project.pbxproj index 8bdf91c..0fdad3d 100644 --- a/UIInputToolbarSample.xcodeproj/project.pbxproj +++ b/UIInputToolbarSample.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0269C506170D6064006A6E46 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0269C504170D6064006A6E46 /* MainWindow-iPad.xib */; }; CA0C9C30137879DA0097DB28 /* UIExpandingTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C9C27137879DA0097DB28 /* UIExpandingTextView.m */; }; CA0C9C31137879DA0097DB28 /* UIExpandingTextViewInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C9C29137879DA0097DB28 /* UIExpandingTextViewInternal.m */; }; CA0C9C32137879DA0097DB28 /* UIInputToolbar.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C9C2B137879DA0097DB28 /* UIInputToolbar.m */; }; @@ -27,6 +28,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0269C505170D6064006A6E46 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = "iPad/en.lproj/MainWindow-iPad.xib"; sourceTree = ""; }; CA0C9C26137879DA0097DB28 /* UIExpandingTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIExpandingTextView.h; sourceTree = ""; }; CA0C9C27137879DA0097DB28 /* UIExpandingTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIExpandingTextView.m; sourceTree = ""; }; CA0C9C28137879DA0097DB28 /* UIExpandingTextViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIExpandingTextViewInternal.h; sourceTree = ""; }; @@ -152,6 +154,7 @@ FF4851E615C67D47003829EC /* toolbarbg.png */, FF4851E715C67D47003829EC /* toolbarbg@2x.png */, CA3A7BA313708CDF00CF5E6B /* MainWindow.xib */, + 0269C504170D6064006A6E46 /* MainWindow-iPad.xib */, ); name = Resources; sourceTree = ""; @@ -211,6 +214,7 @@ FF4851EB15C67D47003829EC /* textbg@2x.png in Resources */, FF4851EC15C67D47003829EC /* toolbarbg.png in Resources */, FF4851ED15C67D47003829EC /* toolbarbg@2x.png in Resources */, + 0269C506170D6064006A6E46 /* MainWindow-iPad.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -233,6 +237,14 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ + 0269C504170D6064006A6E46 /* MainWindow-iPad.xib */ = { + isa = PBXVariantGroup; + children = ( + 0269C505170D6064006A6E46 /* en */, + ); + name = "MainWindow-iPad.xib"; + sourceTree = ""; + }; CA3A7B9A13708CDE00CF5E6B /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( @@ -293,7 +305,9 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UIInputToolbarSample/UIInputToolbarSample-Prefix.pch"; INFOPLIST_FILE = "UIInputToolbarSample/UIInputToolbarSample-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -306,7 +320,9 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UIInputToolbarSample/UIInputToolbarSample-Prefix.pch"; INFOPLIST_FILE = "UIInputToolbarSample/UIInputToolbarSample-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; WRAPPER_EXTENSION = app; }; diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.h b/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.h old mode 100644 new mode 100755 diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.m b/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.m old mode 100644 new mode 100755 index ac45276..540b78f --- a/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.m +++ b/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.m @@ -272,8 +272,6 @@ - (void)textViewDidChange:(UITextView *)textView { [delegate expandingTextViewDidChange:self]; } - - } -(void)growDidStop @@ -290,6 +288,12 @@ -(BOOL)resignFirstResponder return [internalTextView resignFirstResponder]; } +- (BOOL)becomeFirstResponder +{ + [super becomeFirstResponder]; + return [internalTextView becomeFirstResponder]; +} + - (void)dealloc { [internalTextView release]; diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextViewInternal.h b/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextViewInternal.h old mode 100644 new mode 100755 diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextViewInternal.m b/UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextViewInternal.m old mode 100644 new mode 100755 diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.h b/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.h old mode 100644 new mode 100755 index a9da6e5..0ea039b --- a/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.h +++ b/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.h @@ -39,6 +39,8 @@ } - (void)drawRect:(CGRect)rect; +- (BOOL)resignFirstResponder; +- (BOOL)becomeFirstResponder; @property (nonatomic, retain) UIExpandingTextView *textView; @property (nonatomic, retain) UIBarButtonItem *inputButton; diff --git a/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.m b/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.m old mode 100644 new mode 100755 index abf2c42..797578e --- a/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.m +++ b/UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.m @@ -25,6 +25,8 @@ #import "UIInputToolbar.h" +#define ScreenWidth [[UIScreen mainScreen] bounds].size.width + @implementation UIInputToolbar @synthesize textView; @@ -43,6 +45,17 @@ -(void)inputButtonPressed [self.textView clearText]; } +- (BOOL)resignFirstResponder +{ + [self.textView clearText]; + return [self.textView resignFirstResponder]; +} + +- (BOOL)becomeFirstResponder +{ + return [self.textView becomeFirstResponder]; +} + -(void)setupToolbar:(NSString *)buttonLabel { self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin; @@ -70,9 +83,9 @@ -(void)setupToolbar:(NSString *)buttonLabel self.inputButton.enabled = NO; /* Create UIExpandingTextView input */ - self.textView = [[[UIExpandingTextView alloc] initWithFrame:CGRectMake(7, 7, 236, 26)] autorelease]; + self.textView = [[[UIExpandingTextView alloc] initWithFrame:CGRectMake(7, 7, ScreenWidth - button.frame.size.width - 30, 26)] autorelease]; self.textView.internalTextView.scrollIndicatorInsets = UIEdgeInsetsMake(4.0f, 0.0f, 10.0f, 0.0f); - self.textView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; + self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.textView.delegate = self; [self addSubview:self.textView]; @@ -86,7 +99,7 @@ -(void)setupToolbar:(NSString *)buttonLabel -(id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - [self setupToolbar:@"Send"]; + [self setupToolbar:NSLocalizedString(@"Send", nil)]; } return self; } @@ -94,7 +107,7 @@ -(id)initWithFrame:(CGRect)frame -(id)init { if ((self = [super init])) { - [self setupToolbar:@"Send"]; + [self setupToolbar:NSLocalizedString(@"Send", nil)]; } return self; } @@ -118,7 +131,6 @@ - (void)dealloc [super dealloc]; } - #pragma mark - #pragma mark UIExpandingTextView delegate diff --git a/UIInputToolbarSample/Classes/UIInputToolbarViewController.h b/UIInputToolbarSample/Classes/UIInputToolbarViewController.h index 0e96747..ebb5b0e 100644 --- a/UIInputToolbarSample/Classes/UIInputToolbarViewController.h +++ b/UIInputToolbarSample/Classes/UIInputToolbarViewController.h @@ -30,7 +30,7 @@ UIInputToolbar *inputToolbar; @private - BOOL keyboardIsVisible; + float keyboardHeight; } @property (nonatomic, retain) UIInputToolbar *inputToolbar; diff --git a/UIInputToolbarSample/Classes/UIInputToolbarViewController.m b/UIInputToolbarSample/Classes/UIInputToolbarViewController.m index a65f2fd..71a05fd 100644 --- a/UIInputToolbarSample/Classes/UIInputToolbarViewController.m +++ b/UIInputToolbarSample/Classes/UIInputToolbarViewController.m @@ -25,10 +25,8 @@ #import "UIInputToolbarViewController.h" -#define kStatusBarHeight 20 +#define kStatusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height #define kDefaultToolbarHeight 40 -#define kKeyboardHeightPortrait 216 -#define kKeyboardHeightLandscape 140 @implementation UIInputToolbarViewController @@ -45,23 +43,17 @@ - (void)dealloc - (void)loadView { [super loadView]; - - keyboardIsVisible = NO; /* Calculate screen size */ CGRect screenFrame = [[UIScreen mainScreen] applicationFrame]; self.view = [[UIView alloc] initWithFrame:screenFrame]; self.view.backgroundColor = [UIColor whiteColor]; + self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; /* Create toolbar */ self.inputToolbar = [[UIInputToolbar alloc] initWithFrame:CGRectMake(0, screenFrame.size.height-kDefaultToolbarHeight, screenFrame.size.width, kDefaultToolbarHeight)]; [self.view addSubview:self.inputToolbar]; inputToolbar.delegate = self; - inputToolbar.textView.placeholder = @"Placeholder"; -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; + inputToolbar.textView.placeholder = NSLocalizedString(@"Placeholder", nil); } - (void)viewWillAppear:(BOOL)animated @@ -70,14 +62,15 @@ - (void)viewWillAppear:(BOOL)animated /* Listen for keyboard */ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + + [inputToolbar becomeFirstResponder]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; /* No longer listen for keyboard */ - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation @@ -85,65 +78,55 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa return YES; } --(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ +- (void)updateInputViewFrame { CGRect screenFrame = [[UIScreen mainScreen] applicationFrame]; - CGRect r = self.inputToolbar.frame; - if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) - { - r.origin.y = screenFrame.size.height - self.inputToolbar.frame.size.height - kStatusBarHeight; - if (keyboardIsVisible) { - r.origin.y -= kKeyboardHeightPortrait; - } - [self.inputToolbar.textView setMaximumNumberOfLines:13]; - } - else - { - r.origin.y = screenFrame.size.width - self.inputToolbar.frame.size.height - kStatusBarHeight; - if (keyboardIsVisible) { - r.origin.y -= kKeyboardHeightLandscape; - } - [self.inputToolbar.textView setMaximumNumberOfLines:7]; - [self.inputToolbar.textView sizeToFit]; - } - self.inputToolbar.frame = r; -} - -#pragma mark - -#pragma mark Notifications - -- (void)keyboardWillShow:(NSNotification *)notification -{ + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + /* Move the toolbar to above the keyboard */ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; CGRect frame = self.inputToolbar.frame; - if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { - frame.origin.y = self.view.frame.size.height - frame.size.height - kKeyboardHeightPortrait; + + if (UIInterfaceOrientationIsPortrait(orientation)) { + frame.origin.y = screenFrame.size.height - frame.size.height - keyboardHeight; } else { - frame.origin.y = self.view.frame.size.width - frame.size.height - kKeyboardHeightLandscape - kStatusBarHeight; + frame.origin.y = screenFrame.size.width - frame.size.height - keyboardHeight; } - self.inputToolbar.frame = frame; - [UIView commitAnimations]; - keyboardIsVisible = YES; + + self.inputToolbar.frame = frame; } -- (void)keyboardWillHide:(NSNotification *)notification +-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - /* Move the toolbar back to bottom of the screen */ - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationDuration:0.3]; - CGRect frame = self.inputToolbar.frame; - if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { - frame.origin.y = self.view.frame.size.height - frame.size.height; + [self updateInputViewFrame]; + + if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { + [self.inputToolbar.textView setMaximumNumberOfLines:7]; } else { - frame.origin.y = self.view.frame.size.width - frame.size.height; - } - self.inputToolbar.frame = frame; - [UIView commitAnimations]; - keyboardIsVisible = NO; + [self.inputToolbar.textView setMaximumNumberOfLines:7]; + } +} + +#pragma mark - +#pragma mark Notifications +- (void)keyboardWillShow:(NSNotification *)notification +{ + NSDictionary *userInfo = [notification userInfo]; + CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + + keyboardHeight = UIInterfaceOrientationIsPortrait(orientation) ? kbSize.height : kbSize.width; + + [self updateInputViewFrame]; +} + +- (void)keyboardWillHide:(NSNotification *)notification +{ + keyboardHeight = 0; + + [self updateInputViewFrame]; } -(void)inputButtonPressed:(NSString *)inputText diff --git a/UIInputToolbarSample/UIInputToolbarSample-Info.plist b/UIInputToolbarSample/UIInputToolbarSample-Info.plist index 1655267..3f6820f 100644 --- a/UIInputToolbarSample/UIInputToolbarSample-Info.plist +++ b/UIInputToolbarSample/UIInputToolbarSample-Info.plist @@ -32,6 +32,8 @@ NSMainNibFile MainWindow + NSMainNibFile~ipad + MainWindow-iPad UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/UIInputToolbarSample/en.lproj/MainWindow.xib b/UIInputToolbarSample/en.lproj/MainWindow.xib index c159d04..a1db544 100644 --- a/UIInputToolbarSample/en.lproj/MainWindow.xib +++ b/UIInputToolbarSample/en.lproj/MainWindow.xib @@ -1,31 +1,28 @@ - 800 - 10D540 - 760 - 1038.29 - 460.00 + 1552 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 81 + 2083 - + YES - + IBProxyObject + IBUICustomObject + IBUIWindow YES com.apple.InterfaceBuilder.IBCocoaTouchPlugin - YES - - YES - - - YES - + PluginDependencyRecalculationVersion + YES @@ -42,10 +39,12 @@ - 1316 + 1280 {320, 480} + + 1 MSAxIDEAA @@ -82,7 +81,9 @@ YES 0 - + + YES + @@ -117,25 +118,25 @@ YES -1.CustomClassName + -1.IBPluginDependency -2.CustomClassName + -2.IBPluginDependency 2.IBAttributePlaceholdersKey - 2.IBEditorWindowLastContentRect 2.IBPluginDependency 3.CustomClassName 3.IBPluginDependency - + YES UIApplication + com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin YES - - YES - + - {{198, 376}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIInputToolbarSampleAppDelegate com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -144,17 +145,13 @@ YES - - YES - + YES - - YES - + 9 @@ -169,17 +166,16 @@ window UIWindow - - IBProjectSource - UIInputToolbarSampleAppDelegate.h + + window + + window + UIWindow + - - - UIInputToolbarSampleAppDelegate - NSObject - IBUserSource - + IBProjectSource + ./Classes/UIInputToolbarSampleAppDelegate.h @@ -191,8 +187,7 @@ YES - UIInputToolbarSample.xcodeproj 3 - 81 + 2083 diff --git a/UIInputToolbarSample/iPad/en.lproj/MainWindow-iPad.xib b/UIInputToolbarSample/iPad/en.lproj/MainWindow-iPad.xib new file mode 100644 index 0000000..c73f080 --- /dev/null +++ b/UIInputToolbarSample/iPad/en.lproj/MainWindow-iPad.xib @@ -0,0 +1,174 @@ + + + + 1552 + 12D78 + 3084 + 1187.37 + 626.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 2083 + + + YES + IBProxyObject + IBUICustomObject + IBUIWindow + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + IBFilesOwner + IBIPadFramework + + + IBFirstResponder + IBIPadFramework + + + IBIPadFramework + + + + 1316 + + {768, 1024} + + 1 + MSAxIDEAA + + NO + NO + + 2 + + IBIPadFramework + YES + + + + + YES + + + delegate + + + + 4 + + + + window + + + + 5 + + + + + YES + + 0 + + YES + + + + + + 2 + + + YES + + + + + -1 + + + File's Owner + + + 3 + + + + + -2 + + + + + + + YES + + YES + -1.CustomClassName + -1.IBPluginDependency + -2.CustomClassName + -2.IBPluginDependency + 2.IBAttributePlaceholdersKey + 2.IBLastUsedUIStatusBarStylesToTargetRuntimesMap + 2.IBPluginDependency + 3.CustomClassName + 3.IBPluginDependency + + + YES + UIApplication + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + YES + + + + + IBCocoaTouchFramework + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIInputToolbarSampleAppDelegate + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + + + + YES + + + + + 9 + + + 0 + IBIPadFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + 3 + 2083 + +