diff --git a/JSMessagesTableViewController/JSBubbleMessageCell.m b/JSMessagesTableViewController/JSBubbleMessageCell.m index 3f7d998..a12e059 100644 --- a/JSMessagesTableViewController/JSBubbleMessageCell.m +++ b/JSMessagesTableViewController/JSBubbleMessageCell.m @@ -177,7 +177,7 @@ return; UIMenuController *menu = [UIMenuController sharedMenuController]; - [menu setTargetRect:self.bubbleView.frame inView:self]; + [menu setTargetRect:CGRectInset([self.bubbleView bubbleFrame], 0, 4.f) inView:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuWillShow:) @@ -201,6 +201,7 @@ - (void) menuWillHide:(NSNotification *)notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillHideMenuNotification object:nil]; + self.bubbleView.selectedToShowCopyMenu = NO; } - (void) menuWillShow:(NSNotification *)notification @@ -210,6 +211,7 @@ selector:@selector(menuWillHide:) name:UIMenuControllerWillHideMenuNotification object:nil]; + self.bubbleView.selectedToShowCopyMenu = YES; } - (void)dealloc{ diff --git a/JSMessagesTableViewController/JSBubbleView.h b/JSMessagesTableViewController/JSBubbleView.h index fd00943..d42c833 100644 --- a/JSMessagesTableViewController/JSBubbleView.h +++ b/JSMessagesTableViewController/JSBubbleView.h @@ -40,7 +40,7 @@ typedef enum { JSBubbleMessageStyleIncomingSquare, JSBubbleMessageStyleOutgoingDefault, JSBubbleMessageStyleOutgoingDefaultGreen, - JSBubbleMessageStyleOutgoingSquare + JSBubbleMessageStyleOutgoingSquare, } JSBubbleMessageStyle; @@ -53,6 +53,9 @@ typedef enum { #pragma mark - Initialization - (id)initWithFrame:(CGRect)frame bubbleStyle:(JSBubbleMessageStyle)bubbleStyle; +- (CGRect)bubbleFrame; +@property (nonatomic) BOOL selectedToShowCopyMenu; + #pragma mark - Bubble view + (UIImage *)bubbleImageForStyle:(JSBubbleMessageStyle)style; + (UIFont *)font; diff --git a/JSMessagesTableViewController/JSBubbleView.m b/JSMessagesTableViewController/JSBubbleView.m index 1446436..5feb655 100644 --- a/JSMessagesTableViewController/JSBubbleView.m +++ b/JSMessagesTableViewController/JSBubbleView.m @@ -86,16 +86,36 @@ [self setNeedsDisplay]; } +- (void)setSelectedToShowCopyMenu:(BOOL)selectedToShowCopyMenu{ + _selectedToShowCopyMenu = selectedToShowCopyMenu; + [self setNeedsDisplay]; +} + #pragma mark - Drawing -- (void)drawRect:(CGRect)frame -{ - UIImage *image = [JSBubbleView bubbleImageForStyle:self.style]; + +- (CGRect)bubbleFrame{ CGSize bubbleSize = [JSBubbleView bubbleSizeForText:self.text]; CGRect bubbleFrame = CGRectMake(([self styleIsOutgoing] ? self.frame.size.width - bubbleSize.width : 0.0f), kMarginTop, bubbleSize.width, bubbleSize.height); - + return bubbleFrame; +} + +- (void)drawRect:(CGRect)frame +{ + UIImage *image = nil; + if (self.selectedToShowCopyMenu) { + if ([self styleIsOutgoing]) { + image = [[UIImage imageNamed:@"messageBubbleHighlighted"] stretchableImageWithLeftCapWidth:15 topCapHeight:15]; + } else { + image = [[UIImage imageNamed:@"messageBubbleSelected"] stretchableImageWithLeftCapWidth:23 topCapHeight:15]; + } + } else { + image = [JSBubbleView bubbleImageForStyle:self.style]; + } + [JSBubbleView bubbleImageForStyle:self.style]; + CGRect bubbleFrame = [self bubbleFrame]; [image drawInRect:bubbleFrame]; CGSize textSize = [JSBubbleView textSizeForText:self.text]; diff --git a/JSMessagesTableViewController/JSMessagesViewController.m b/JSMessagesTableViewController/JSMessagesViewController.m index 4cde8a3..63c328c 100644 --- a/JSMessagesTableViewController/JSMessagesViewController.m +++ b/JSMessagesTableViewController/JSMessagesViewController.m @@ -271,7 +271,9 @@ BOOL isShrinking = textViewContentHeight < self.previousTextViewContentHeight; CGFloat changeInHeight = textViewContentHeight - self.previousTextViewContentHeight; - changeInHeight = (textViewContentHeight + changeInHeight >= maxHeight) ? 0.0f : changeInHeight; + if (changeInHeight > 0 && self.previousTextViewContentHeight == maxHeight) { + changeInHeight = 0; + } if(!isShrinking) [self.inputToolBarView adjustTextViewHeightBy:changeInHeight]; diff --git a/JSMessagesTableViewController/Resources/Images/messageBubbleSelected.png b/JSMessagesTableViewController/Resources/Images/messageBubbleSelected.png new file mode 100644 index 0000000..13c9962 Binary files /dev/null and b/JSMessagesTableViewController/Resources/Images/messageBubbleSelected.png differ diff --git a/JSMessagesTableViewController/Resources/Images/messageBubbleSelected@2x.png b/JSMessagesTableViewController/Resources/Images/messageBubbleSelected@2x.png new file mode 100644 index 0000000..61aa572 Binary files /dev/null and b/JSMessagesTableViewController/Resources/Images/messageBubbleSelected@2x.png differ diff --git a/MessagesDemo.xcodeproj/project.pbxproj b/MessagesDemo.xcodeproj/project.pbxproj index ccb1b29..67f76c8 100644 --- a/MessagesDemo.xcodeproj/project.pbxproj +++ b/MessagesDemo.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 049A2A3717A16EA0000D4811 /* messageBubbleSelected.png in Resources */ = {isa = PBXBuildFile; fileRef = 049A2A3517A16E9E000D4811 /* messageBubbleSelected.png */; }; + 049A2A3817A16EA0000D4811 /* messageBubbleSelected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 049A2A3617A16E9F000D4811 /* messageBubbleSelected@2x.png */; }; 881AE55D16D13CDC008F7636 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 881AE55C16D13CDC008F7636 /* UIKit.framework */; }; 881AE55F16D13CDC008F7636 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 881AE55E16D13CDC008F7636 /* Foundation.framework */; }; 881AE56116D13CDC008F7636 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 881AE56016D13CDC008F7636 /* CoreGraphics.framework */; }; @@ -54,6 +56,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 049A2A3517A16E9E000D4811 /* messageBubbleSelected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = messageBubbleSelected.png; sourceTree = ""; }; + 049A2A3617A16E9F000D4811 /* messageBubbleSelected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "messageBubbleSelected@2x.png"; sourceTree = ""; }; 881AE55916D13CDC008F7636 /* MessagesDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MessagesDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 881AE55C16D13CDC008F7636 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 881AE55E16D13CDC008F7636 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -222,6 +226,8 @@ 88301EF216F77B3D0037524D /* Images */ = { isa = PBXGroup; children = ( + 049A2A3517A16E9E000D4811 /* messageBubbleSelected.png */, + 049A2A3617A16E9F000D4811 /* messageBubbleSelected@2x.png */, 88244C0116FE5BA300034667 /* bubbleSquareIncoming.png */, 88244C0216FE5BA300034667 /* bubbleSquareIncoming@2x.png */, 88244C0316FE5BA300034667 /* bubbleSquareOutgoing.png */, @@ -337,6 +343,8 @@ 88244C0616FE5BA400034667 /* bubbleSquareIncoming@2x.png in Resources */, 88244C0716FE5BA400034667 /* bubbleSquareOutgoing.png in Resources */, 88244C0816FE5BA400034667 /* bubbleSquareOutgoing@2x.png in Resources */, + 049A2A3717A16EA0000D4811 /* messageBubbleSelected.png in Resources */, + 049A2A3817A16EA0000D4811 /* messageBubbleSelected@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };