Doble toque uitextview

Solo quiero que mi uitextview se pueda editar si el usuario hace un doble clic sobre él.

Pero en mi código solo funciona una vez. Después de ocultar el keyboard, el doble toque deja de funcionar como quiero. Solo muestra la window emergente "copyr y definir", si lo bash por segunda vez …

Tal vez el "textViewDidEndEditing" no es la forma correcta para esto …

Aquí está el Código:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CGFloat screen_height = [UIScreen mainScreen].bounds.size.height; CGFloat screen_width = [UIScreen mainScreen].bounds.size.width; scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0,screen_width,screen_height)]; scrollView.showsVerticalScrollIndicator=NO; scrollView.scrollEnabled=NO; scrollView.userInteractionEnabled=YES; [scrollView setBackgroundColor:[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.5]]; [self.view addSubview:scrollView]; scrollView.contentSize = CGSizeMake(screen_width,screen_height); MyTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, screen_width, screen_height)]; MyTextView.text = @"Headline\nNo1"; MyTextView.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; [MyTextView setFont:[UIFont fontWithName:@"Helvetica" size:90]]; MyTextView.textAlignment = NSTextAlignmentCenter; MyTextView.delegate = self; [MyTextView setScrollEnabled:NO]; [MyTextView setEditable:NO]; [MyTextView setUserInteractionEnabled:YES]; [MyTextView setBackgroundColor:[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0]]; [MyTextView sizeToFit]; [scrollView addSubview:MyTextView]; // TAP UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)]; [doubleTap setNumberOfTapsRequinetworking:2]; [doubleTap setNumberOfTouchesRequinetworking:1]; [MyTextView addGestureRecognizer:doubleTap]; // KEYBOARD [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)doubleTap:(UITapGestureRecognizer *)sender { NSLog(@"View: %@", [[sender view] class]); UITextView *tappedView = (UITextView *)[sender view]; [tappedView setEditable:YES]; [tappedView becomeFirstResponder]; } -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { if (((UITapGestureRecognizer *)gestureRecognizer).numberOfTapsRequinetworking == 2) { return YES; } } return YES; } -(BOOL)canBecomeFirstResponder { if (MyTextView.editable == YES) { return YES; } else { return NO; } } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGesture { return YES; } -(void)textViewDidEndEditing:(UITextView *)textView { [textView setEditable:NO]; } -(void)keyboardDidHide:(NSNotification *)aNotification { NSLog(@"keyboardDidHide"); // [textView setEditable:NO]; // same result like textViewDidEndEditing } 

Eliminar / comentar [textView setEditable:NO]; del método
-(void)textViewDidEndEditing:(UITextView *)textView .

Este es el único que te causa problemas. porque la mejor manera de detener el modo de edición de UITextView / UItextField es la resignFirstReponder método resignFirstReponder .

EDITAR

Para ocultar el keyboard, agregue las siguientes líneas en el método viewDidLoad

 UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)]; [self.view addGestureRecognizer:singleTap]; 

Que agregue hideKeyboard siguiente manera

 -(void) hideKeyboard { [MyTextView resignFirstResponder]; } 

Las cosas serán simples si agrega una vista clara sobre la vista de text y agrega un gesto de doble toque en la vista clara. Cuando se reconoce doble toque, elimine la vista clara y haga que textview sea el primero en responder

 [clearView removeFromSuperview] ; [textview becomeFirstResponder] ;