如何通过点击并按住事件复制 UITextField?

发布于 2025-01-04 13:46:14 字数 81 浏览 1 评论 0原文

我有几个 UITextFields 设置可以在屏幕上移动,并且可以通过双击进行编辑。我想知道是否有办法点击并按住 UITextField 来复制它?

I have several UITextFields setup to move around the screen and are editable with a double tap. I was wondering if there was a way to tap and hold the UITextField to copy it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心如荒岛 2025-01-11 13:46:14

您是否尝试过在文本字段上长按手势?您可以从中复制文本,但我不确定文本选择。

下面的代码是用长按手势注册文本字段。

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];                                                
[textField addGestureRecognizer:longPress];

然后识别长按时的回调函数:

-(void)longPressed:(UILongPressGestureRecognizer *)sender
{
     NsLog(@"Text from text field is %@",((UITextField *)[sender view]).text);
}

试试这个。

Did you try long press gesture on the text field? You can copy the text from it, though I am not sure of the text selection.

The below code is to register textfield with the long press gesture.

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];                                                
[textField addGestureRecognizer:longPress];

Then callback function when the long press is recognized:

-(void)longPressed:(UILongPressGestureRecognizer *)sender
{
     NsLog(@"Text from text field is %@",((UITextField *)[sender view]).text);
}

Try this out.

时光倒影 2025-01-11 13:46:14

设置一个 UILongPressGestureRecognizer: 并查看 textFieldShouldBeginEditing: 是否也被触发?如果是,那么您只需复制其中的文本字段即可。我不知道是否会触发或者手势识别器是否会“超越”它?

set up a UILongPressGestureRecognizer: and see if textFieldShouldBeginEditing: is fired also? if it is, then you can just copy the text field in there. i have no idea if will fire or if the gesture recognizer would "over ride" it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文