当我在UITextfield中写一些东西并双击它时,它会在ios设备上显示"选择"、"全选"、"粘贴"选项。我想通过编程显示相同的消息。
有人能提出做这件事的方法吗?
双击不会因以下代码而起火。
+(void)performanualTouch:(UITouch*)touch {
UIEvent *eventDown = [[UIEvent alloc] initWithTouch:touch];
for (UIGestureRecognizer* gr in touch.view.gestureRecognizers) {
if ([gr isKindOfClass:[UITapGestureRecognizer class]]) {
[gr touchesBegan:[eventDown allTouches] withEvent:eventDown];
[touch setThePhase:UITouchPhaseEnded];
UIEvent *eventUp = [[UIEvent alloc] initWithTouch:touch];
[gr touchesEnded:[eventUp allTouches] withEvent:eventUp];
[eventUp release];
if (gr.cancelsTouchesInView) {
return;
}
}
}
[touch.view touchesBegan:[eventDown allTouches] withEvent:eventDown];
[[UIApplication sharedApplication] sendEvent:eventDown];
[touch setThePhase:UITouchPhaseEnded];
UIEvent *eventUp = [[UIEvent alloc] initWithTouch:touch];
[touch.view touchesEnded:[eventUp allTouches] withEvent:eventUp];
[[UIApplication sharedApplication] sendEvent:eventUp];
[eventDown release];
[eventUp release];
}
感谢
您可以在这里找到涵盖这一特殊需求的文档
相关部分:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if ([theTouch tapCount] == 2 && [self becomeFirstResponder]) {
// selection management code goes here...
// bring up edit menu.
UIMenuController *theMenu = [UIMenuController sharedMenuController];
CGRect selectionRect = CGRectMake (currentSelection.x, currentSelection.y, SIDE, SIDE);
[theMenu setTargetRect:selectionRect inView:self];
[theMenu setMenuVisible:YES animated:YES];
}
}