How to add the system's menu in your gesture? php
What you should do must same with this: this
1) - (BOOL)canBecomeFirstResponder must return YES; spa
2) - (BOOL)canPerformAction:(SEL)action withSender:(id)sender what you want to show item should return YES; code
3) Before you show the menu, you should call the method: [self becomeFirstResponder]; orm
4) If you want to show the second menu, you should call the method "setMenuVisible:NO",otherwise the menu will not show. get
This is the whole view controller .m file content, nothing content in the .h file. it
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGesture:)]; [self.view addGestureRecognizer:longGesture]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (BOOL)canBecomeFirstResponder { return YES; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(copy:)) { return YES; } return NO; } - (void)longGesture:(UILongPressGestureRecognizer *)longGesture { if (longGesture.state == UIGestureRecognizerStateBegan) {[self becomeFirstResponder]; UIMenuController *menuController = [UIMenuController sharedMenuController]; [menuController setTargetRect:CGRectMake(0, 0, 50, 50) inView:self.view]; [menuController setMenuVisible:YES animated:YES]; } } - (void)copy:(id)sneder { } - (void)delete:(id)sender {} - (void)move:(id)sender {} @end
Reference Link:http://www.cocoachina.com/bbs/read.php?tid=75860&keyword=menucontroller io
Thanks, form
Blues class