Disable Magnifying Glass in UITextview

This works for me

@implementation CustomTextView 

- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
    self.selectedTextRange = nil;
    return nil;
}

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
    gestureRecognizer.delegate = self;

    [super addGestureRecognizer:gestureRecognizer];
    return;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return NO;
}

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return [super caretRectForPosition:self.endOfDocument];
}


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && !gestureRecognizer.delaysTouchesEnded))
    {
        return NO;
    }
    else
        return YES;

}

Swift 4 version of @user1120133's answer:

    override func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) {
      //Prevent long press to show the magnifying glass
      if gestureRecognizer is UILongPressGestureRecognizer {
        gestureRecognizer.isEnabled = false
      }

      super.addGestureRecognizer(gestureRecognizer)
    }

Finally this issue is also resolved

Here is the code for reference in case anyone needs

in the m file of subclassed UITextview added code

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

It works.


Xamarin.iOS:

  1. Create custom UITextView
  2. Override GestureRecognizerShouldBegin method on your UITextView
public override bool GestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer)
{
    if (gestureRecognizer is UILongPressGestureRecognizer ||
        gestureRecognizer.Name != "UITextInteractionNameLinkTap")
    {
        return false;
    }
    return true;
}