In UITextview
when touch is pressed for the longer time magnifying glass shows up. How can i disable it.
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.
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With