Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Magnifying Glass in UITextview

In UITextview when touch is pressed for the longer time magnifying glass shows up. How can i disable it.

like image 796
user1120133 Avatar asked May 17 '12 17:05

user1120133


3 Answers

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.

like image 59
user1120133 Avatar answered Oct 14 '22 19:10

user1120133


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;

}
like image 1
Irina Didkovskaya Avatar answered Oct 14 '22 17:10

Irina Didkovskaya


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)
    }
like image 1
Bill Chan Avatar answered Oct 14 '22 19:10

Bill Chan