【问题标题】:Message bubble copy paste like whats app for iPhone application消息气泡复制粘贴,如 iPhone 应用程序的什么应用程序
【发布时间】:2013-09-24 13:04:30
【问题描述】:

我的项目中有短信回复屏幕,与什么应用程序相同。屏幕包含消息气泡和“文本视图”,用于输入用户想要发送的消息和发送按钮。我正在尝试编写代码以使复制/粘贴消息气泡与什么应用程序相同。我在网上看到了一个名为“可复制单元格”的演示代码,它使用长按手势来复制表格视图单元格的内容。当我尝试复制消息气泡时,该单元格将成为第一响应者,而“文本视图”将成为响应者,因为该键盘已隐藏。所以当键盘可见时我无法复制消息气泡。我也尝试过使用其他临时文本字段,但它不起作用。我想要适用于 iOS5、6 和 7 的解决方案。请帮忙。谢谢。

【问题讨论】:

  • 查找 UIPasteBoard。我自己从未使用过它,但我知道这就是您要找的东西。
  • 我试过了,但问题是每次复制时键盘都会退出。有什么解决办法吗?
  • 您的 UITextView 子类应覆盖 canResignFirstResponder 以返回 NO

标签: iphone ios ios6 ios7 messages


【解决方案1】:
@interface TestViewController ()

@property (strong, nonatomic) UITextView *textView;

@end

@implementation TestViewController

- (void)copyAction {
   /* Copies the string from the textView into the UIPasteBoard */

    UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
    pasteBoard.persistent = YES;
    [appPasteBoard setString:self.textView.text];

}

- (NSString *)stringInPasteBoard {
    /* Returns the string in the UIPasteBoard if any */

    UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];

    if([pasteBoard string] != NULL && [pasteBoard string].length > 0)
      return [pasteBoard string];


     return nil;

}

@end

【讨论】:

  • 不是这样。我想要像什么应用一样复制/粘贴。我希望键盘在复制 SMS 气泡时保持活动状态。
  • 通过不允许 firstResponder 关闭键盘来控制它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-01
  • 2011-03-05
  • 1970-01-01
相关资源
最近更新 更多