How can I get a standard bubble to copy iPhone to UIImage?

In iPhoto, I can simply drag my finger across the image to get a Copy pop-up (for example, the pop-up that you see in text boxes).

In my UIImageView this is not the case. How to enable it?

+6
ios clipboard copy uiimage uipasteboard
source share
1 answer

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

 [self becomeFirstResponder]; UIMenuController *copyMenuController = [UIMenuController sharedMenuController]; [copyMenuController setTargetRect:image.frame inView:self.view]; [copyMenuController setMenuVisible:YES animated:YES]; 

It is assumed that this code will be implemented in the UIViewController for the view on which your image is placed.

To enable various menu items, you also need to implement several 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" option will be enabled. You will also need to implement the appropriate -copy method: to handle what happens when the user selects this menu item.

+16
source share

All Articles