Permalink
Browse files

Changes to example to add new messages

  • Loading branch information...
1 parent 67235ca commit bc0dc5b151241c4ae476c894e23800156e9709a8 Alex Barinov committed Nov 16, 2012
@@ -11,13 +11,6 @@
#import <UIKit/UIKit.h>
#import "UIBubbleTableViewDataSource.h"
-@class UIBubbleTableView;
-
@interface ViewController : UIViewController <UIBubbleTableViewDataSource>
-{
- IBOutlet UIBubbleTableView *bubbleTable;
-
- NSMutableArray *bubbleData;
-}
@end
@@ -19,6 +19,17 @@
#import "UIBubbleTableViewDataSource.h"
#import "NSBubbleData.h"
+@interface ViewController ()
+{
+ IBOutlet UIBubbleTableView *bubbleTable;
+ IBOutlet UIView *textInputView;
+ IBOutlet UITextField *textField;
+
+ NSMutableArray *bubbleData;
+}
+
+@end
+
@implementation ViewController
- (void)viewDidLoad
@@ -31,7 +42,7 @@ - (void)viewDidLoad
NSBubbleData *photoBubble = [NSBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse];
photoBubble.avatar = [UIImage imageNamed:@"avatar1.png"];
- NSBubbleData *replyBubble = [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
+ NSBubbleData *replyBubble = [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:-5] type:BubbleTypeMine];
replyBubble.avatar = nil;
bubbleData = [[NSMutableArray alloc] initWithObjects:heyBubble, photoBubble, replyBubble, nil];
@@ -57,11 +68,11 @@ - (void)viewDidLoad
bubbleTable.typingBubble = NSBubbleTypingTypeSomebody;
[bubbleTable reloadData];
-}
-
-- (void)viewDidUnload
-{
- [super viewDidUnload];
+
+ // Keyboard events
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
@@ -81,4 +92,54 @@ - (NSBubbleData *)bubbleTableView:(UIBubbleTableView *)tableView dataForRow:(NSI
return [bubbleData objectAtIndex:row];
}
+#pragma mark - Keyboard events
+
+- (void)keyboardWasShown:(NSNotification*)aNotification
+{
+ NSDictionary* info = [aNotification userInfo];
+ CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
+
+ [UIView animateWithDuration:0.2f animations:^{
+
+ CGRect frame = textInputView.frame;
+ frame.origin.y -= kbSize.height;
+ textInputView.frame = frame;
+
+ frame = bubbleTable.frame;
+ frame.size.height -= kbSize.height;
+ bubbleTable.frame = frame;
+ }];
+}
+
+- (void)keyboardWillBeHidden:(NSNotification*)aNotification
+{
+ NSDictionary* info = [aNotification userInfo];
+ CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
+
+ [UIView animateWithDuration:0.2f animations:^{
+
+ CGRect frame = textInputView.frame;
+ frame.origin.y += kbSize.height;
+ textInputView.frame = frame;
+
+ frame = bubbleTable.frame;
+ frame.size.height += kbSize.height;
+ bubbleTable.frame = frame;
+ }];
+}
+
+#pragma mark - Actions
+
+- (IBAction)sayPressed:(id)sender
+{
+ bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
+
+ NSBubbleData *sayBubble = [NSBubbleData dataWithText:textField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
+ [bubbleData addObject:sayBubble];
+ [bubbleTable reloadData];
+
+ textField.text = @"";
+ [textField resignFirstResponder];
+}
+
@end
Oops, something went wrong.

0 comments on commit bc0dc5b

Please sign in to comment.