2013-11-22 1 views
0

Когда я пишу что-то в UITextfield и дважды нажимаю на него, он показывает опцию «Выбрать», «Выбрать ВСЕ», «Вставить» на устройстве ios. Я хочу отображать такое же сообщение через программирование.Как имитировать двойной щелчок на UITextField?

Может ли кто-нибудь предложить способ сделать это?

Двойной контакт не срабатывает с кодом ниже.

+(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]; 

} 

Благодаря

+0

Это должно помочь вам достаточно [ссылка] (HTTP: // StackOverflow .com/вопросы/8277535/КСН-хау к Simulate-два-краны-на-UITextView-программно). –

ответ

0

Вы можете найти документацию, охватывающую эту конкретную потребность here

Соответствующая часть:

- (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]; 

} 
}