- (void)setupUI {
self.tapView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
self.tapView.center = self.view.center;
self.tapView.backgroundColor = [UIColor redColor];
UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longTap)];
[self.tapView addGestureRecognizer:recognizer];
[self.view addSubview:self.tapView];
}
- (void)longTap {
[self becomeFirstResponder];
UIMenuController *menuControler = [UIMenuController sharedMenuController];
UIMenuItem *item = [[UIMenuItem alloc] initWithTitle:@"ccccccccccc" action:@selector(copyToPasteBoard)];
[menuControler setMenuItems:[NSArray arrayWithObjects:item, nil]];
menuControler.arrowDirection = UIMenuControllerArrowUp;
[menuControler setMenuVisible:NO];
[menuControler setTargetRect:self.tapView.frame inView:self.view];
[menuControler setMenuVisible:YES animated:YES];
}
- (void)copyToPasteBoard {
UIPasteboard *board = [UIPasteboard generalPasteboard];
board.string = @"Test String";
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action != @selector(copyToPasteBoard)) {
return NO;
}
return YES;
}
网友评论