3

I want to get rid of magnification and text selection in UITextView but I need phone number, link and address detectors. I am using

-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
    if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
        gestureRecognizer.enabled = NO;
    }
    [super addGestureRecognizer:gestureRecognizer];
    return;}

to stop magnification, but it also stops selection phone number / address / link detected by textview. If I do [_txtView setSelectable:NO]; it stops both magnification and text selection as well as data detection.

Umang
  • 129
  • 1
  • 3
  • 9

4 Answers4

2

After quite a long time trying, I managed to stop text selection, magnifying, and keeping data detection (links clickable etc) by overriding addGestureRecognizer on a UITextView subclass allowing only UILongPressGestureRecognizer delaying touch ending:

UIUnselectableTextView.m

-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
    if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && gestureRecognizer.delaysTouchesEnded)
    {
        [super addGestureRecognizer:gestureRecognizer];
    }
}
Thibaud David
  • 496
  • 2
  • 11
1

Put image on your UITextview in .xib file then put below code.

 - (void)viewDidLoad
  {
      [super viewDidLoad];
      self.navigationController.navigationBarHidden = YES;

      UITapGestureRecognizer *tappress= [[UITapGestureRecognizer alloc] initWithTarget:self    action:@selector(longPressed:)];
      img.userInteractionEnabled = YES;
      [img addGestureRecognizer:tappress];
}

-(void)longPressed:(UILongPressGestureRecognizer *)sender
{
    [yourtextview becomeFirstResponder];
}

in my code img is a UIImageview

Hardik Kardani
  • 576
  • 3
  • 24
0

Try this:

  1. Set the delegate of the textview to your viewcontroller
  2. add this method

    - (void)textViewDidChangeSelection:(UITextView *)textView
    {
         NSRange selected;
         selected.location = 0;
         selected.length = 0;
         textView.selectedRange = selected;
    }
    

This would disable the magnification but still have links clickable

Ruchi
  • 49
  • 3
-3

You just need to make sure you have set right parameters for the UItextfield (and there is no need to actually have it done by overriding the gestures). I guess if you change your attributes for "Behaviour" and "Detection" in interface builder as following you will have your desired behaviour.enter image description here

  • 2
    if Selectable is unchecked detection doesn't work even if all the detection are marked as checked – Umang Jul 18 '14 at 11:14