1

UITextView に埋め込まれている UIImageView からカスタム UIMenuController を表示しようとしています。

どうすればこれを達成できますか?

下の画像に示すように、[切り取り]、[コピー]、[貼り付け]、[選択]、[すべて選択] のメニューが表示されます。 ここに画像の説明を入力

さらにタップした場合にのみ、必要なものが得られます。 ここに画像の説明を入力

これが私のコードの一部です:

@interface UIImageView (Extended)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)canBecomeFirstResponder;
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender;

@end

@implementation UIImageView (Extended)

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {

if (action == @selector(copy:) || action == @selector(paste:) || action == @selector(cut:) || action == @selector(delete:) || 
        action == @selector(select:) || action == @selector(selectAll:)) {
return YES; 
}

return NO;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[self.nextResponder touchesBegan:touches withEvent:event];

}

@end

- (void)showMenuController {

UIMenuController *sharedController = [UIMenuController sharedMenuController];
UIMenuItem *moreOptionsItem = [[UIMenuItem alloc] initWithTitle:@"More options" action:@selector(imageMenuItemPressedMore:)];
UIMenuItem *cut = [[UIMenuItem alloc] initWithTitle:@"Cut" action:@selector(cutImageItemPressed:)];
UIMenuItem *copy_item = [[UIMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyImagePressed:)];
UIMenuItem *paste = [[UIMenuItem alloc] initWithTitle:@"Paste" action:@selector(pasteImagePressed:)];
UIMenuItem *crop = [[UIMenuItem alloc] initWithTitle:@"Crop" action:@selector(cropImagePressed:)];

sharedController.menuItems = [NSArray arrayWithObjects:cut, copy_item, paste, crop, moreOptionsItem, nil];

[moreOptionsItem release];
[cut release];
[copy_item release];
[paste release];
[crop release];


[sharedController setTargetRect:CGRectMake(theView.frame.size.width/2, 0, 0, 0) inView:theView];
[sharedController setMenuVisible:YES animated:YES];

}

私は何を間違っていますか?どんな助けでも感謝します。

4

0 に答える 0