mirror of
https://github.com/zhigang1992/MessagesTableViewController.git
synced 2026-01-12 22:48:53 +08:00
Get the Copy up and working, but the inputView is jumpy.
This commit is contained in:
@@ -65,6 +65,11 @@
|
||||
self.textLabel.hidden = YES;
|
||||
self.detailTextLabel.text = nil;
|
||||
self.detailTextLabel.hidden = YES;
|
||||
|
||||
UILongPressGestureRecognizer *recognizer =
|
||||
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
|
||||
[recognizer setMinimumPressDuration:0.5];
|
||||
[self addGestureRecognizer:recognizer];
|
||||
}
|
||||
|
||||
- (void)configureTimestampLabel
|
||||
@@ -139,4 +144,76 @@
|
||||
timeStyle:NSDateFormatterShortStyle];
|
||||
}
|
||||
|
||||
#pragma mark - Implement Copy
|
||||
- (BOOL) canBecomeFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL) becomeFirstResponder
|
||||
{
|
||||
return [super becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender
|
||||
{
|
||||
if (action == @selector(copy:))
|
||||
return YES;
|
||||
|
||||
return [super canPerformAction:action withSender:sender];
|
||||
}
|
||||
|
||||
- (void)copy:(id)sender {
|
||||
[[UIPasteboard generalPasteboard] setString:self.bubbleView.text];
|
||||
[self resignFirstResponder];
|
||||
}
|
||||
|
||||
- (void) handleLongPress:(UILongPressGestureRecognizer *)longPressRecognizer
|
||||
{
|
||||
if (longPressRecognizer.state != UIGestureRecognizerStateBegan)
|
||||
return;
|
||||
|
||||
if ([self becomeFirstResponder] == NO)
|
||||
return;
|
||||
|
||||
UIMenuController *menu = [UIMenuController sharedMenuController];
|
||||
[menu setTargetRect:self.bubbleView.frame inView:self];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(menuWillShow:)
|
||||
name:UIMenuControllerWillShowMenuNotification
|
||||
object:nil];
|
||||
[menu setMenuVisible:YES animated:YES];
|
||||
}
|
||||
|
||||
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[super touchesEnded:touches withEvent:event];
|
||||
if ([self isFirstResponder] == NO)
|
||||
return;
|
||||
|
||||
UIMenuController *menu = [UIMenuController sharedMenuController];
|
||||
[menu setMenuVisible:NO animated:YES];
|
||||
[menu update];
|
||||
[self resignFirstResponder];
|
||||
}
|
||||
|
||||
- (void) menuWillHide:(NSNotification *)notification
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillHideMenuNotification object:nil];
|
||||
}
|
||||
|
||||
- (void) menuWillShow:(NSNotification *)notification
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillShowMenuNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(menuWillHide:)
|
||||
name:UIMenuControllerWillHideMenuNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user