如何获得标准的iPhone复制气泡出现在UIImage

如何获得标准的iPhone复制气泡出现在UIImage

本文介绍了如何获得标准的iPhone复制气泡出现在UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhoto中,我可以直接在图片上按住手指以获得复制弹出式窗口(例如您在文本框中看到的弹出式窗口)。

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

UIImageView的,这不是这样的。如何启用?

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

推荐答案

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

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;
}

在这种情况下,只会启用复制菜单选项。您还需要实现相应的-copy:方法来处理用户选择该菜单项时会发生什么。

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.

这篇关于如何获得标准的iPhone复制气泡出现在UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:00