Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions UIInputToolbarSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
CA0C9C26137879DA0097DB28 /* UIExpandingTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIExpandingTextView.h; sourceTree = "<group>"; };
CA0C9C27137879DA0097DB28 /* UIExpandingTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIExpandingTextView.m; sourceTree = "<group>"; };
CA0C9C28137879DA0097DB28 /* UIExpandingTextViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIExpandingTextViewInternal.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -152,6 +154,7 @@
FF4851E615C67D47003829EC /* toolbarbg.png */,
FF4851E715C67D47003829EC /* toolbarbg@2x.png */,
CA3A7BA313708CDF00CF5E6B /* MainWindow.xib */,
0269C504170D6064006A6E46 /* MainWindow-iPad.xib */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand All @@ -233,6 +237,14 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
0269C504170D6064006A6E46 /* MainWindow-iPad.xib */ = {
isa = PBXVariantGroup;
children = (
0269C505170D6064006A6E46 /* en */,
);
name = "MainWindow-iPad.xib";
sourceTree = "<group>";
};
CA3A7B9A13708CDE00CF5E6B /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
Empty file.
8 changes: 6 additions & 2 deletions UIInputToolbarSample/Classes/UIInputToolbar/UIExpandingTextView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ - (void)textViewDidChange:(UITextView *)textView
{
[delegate expandingTextViewDidChange:self];
}


}

-(void)growDidStop
Expand All @@ -290,6 +288,12 @@ -(BOOL)resignFirstResponder
return [internalTextView resignFirstResponder];
}

- (BOOL)becomeFirstResponder
{
[super becomeFirstResponder];
return [internalTextView becomeFirstResponder];
}

- (void)dealloc
{
[internalTextView release];
Expand Down
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
}

- (void)drawRect:(CGRect)rect;
- (BOOL)resignFirstResponder;
- (BOOL)becomeFirstResponder;

@property (nonatomic, retain) UIExpandingTextView *textView;
@property (nonatomic, retain) UIBarButtonItem *inputButton;
Expand Down
22 changes: 17 additions & 5 deletions UIInputToolbarSample/Classes/UIInputToolbar/UIInputToolbar.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#import "UIInputToolbar.h"

#define ScreenWidth [[UIScreen mainScreen] bounds].size.width

@implementation UIInputToolbar

@synthesize textView;
Expand All @@ -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;
Expand Down Expand Up @@ -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];

Expand All @@ -86,15 +99,15 @@ -(void)setupToolbar:(NSString *)buttonLabel
-(id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[self setupToolbar:@"Send"];
[self setupToolbar:NSLocalizedString(@"Send", nil)];
}
return self;
}

-(id)init
{
if ((self = [super init])) {
[self setupToolbar:@"Send"];
[self setupToolbar:NSLocalizedString(@"Send", nil)];
}
return self;
}
Expand All @@ -118,7 +131,6 @@ - (void)dealloc
[super dealloc];
}


#pragma mark -
#pragma mark UIExpandingTextView delegate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
UIInputToolbar *inputToolbar;

@private
BOOL keyboardIsVisible;
float keyboardHeight;
}

@property (nonatomic, retain) UIInputToolbar *inputToolbar;
Expand Down
101 changes: 42 additions & 59 deletions UIInputToolbarSample/Classes/UIInputToolbarViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -70,80 +62,71 @@ - (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
{
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
Expand Down
2 changes: 2 additions & 0 deletions UIInputToolbarSample/UIInputToolbarSample-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>NSMainNibFile~ipad</key>
<string>MainWindow-iPad</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
Loading