如何让标准 iPhone 复制气泡出现在 UIImage 上?

发布于 2024-08-07 13:13:09 字数 104 浏览 5 评论 0原文

在 iPhoto 中,我只需将手指放在图像上即可获得“复制”弹出窗口(就像您在文本框中看到的弹出窗口一样)。

在我的 UIImageView 中,情况并非如此。我怎样才能启用它?

In iPhoto, I can simply hold my finger over an image to get a "Copy" popup (like the popup you see in text boxes).

In my UIImageView's, this is not the case. How can I enable it?

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

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

发布评论

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

评论(1

滥情稳全场 2024-08-14 13:13:09

您可以使用 UIMenuController。例如,以下代码将显示以图像为中心的菜单:

[self becomeFirstResponder];

UIMenuController *copyMenuController = [UIMenuController sharedMenuController];

[copyMenuController setTargetRect:image.frame inView:self.view];
[copyMenuController setMenuVisible:YES animated:YES];

假设您将在 UIViewController 用于托管图像的视图。

要启用各种菜单项,您还需要在控制器中实现一些委托方法:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{   
    if (action == @selector(cut:))
        return NO;
    else if (action == @selector(copy:))
        return YES;
    else if (action == @selector(paste:))
        return NO;
    else if (action == @selector(select:) || action == @selector(selectAll:)) 
        return NO;
    else
        return [super canPerformAction:action withSender:sender];
}

- (BOOL)canBecomeFirstResponder 
{
    return YES;
}

在这种情况下,仅启用“复制”菜单选项。您还需要实现适当的 -copy: 方法来处理用户选择该菜单项时发生的情况。

You can manually display the Cut / Copy / Paste menu using the UIMenuController class. For example, the following code will display the menu, centered on your image:

[self becomeFirstResponder];

UIMenuController *copyMenuController = [UIMenuController sharedMenuController];

[copyMenuController setTargetRect:image.frame inView:self.view];
[copyMenuController setMenuVisible:YES animated:YES];

This assumes that you'll be implementing this code in a UIViewController for the view that hosts your image.

To enable the various menu items, you'll also need to implement a few delegate methods in your controller:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{   
    if (action == @selector(cut:))
        return NO;
    else if (action == @selector(copy:))
        return YES;
    else if (action == @selector(paste:))
        return NO;
    else if (action == @selector(select:) || action == @selector(selectAll:)) 
        return NO;
    else
        return [super canPerformAction:action withSender:sender];
}

- (BOOL)canBecomeFirstResponder 
{
    return YES;
}

In this case, only the Copy menu option will be enabled. You'll also need to implement the appropriate -copy: method to handle what happens when the user selects that menu item.

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