Randy Randy - 11 months ago 41
iOS Question

How to disable hold and scroll on a UITextField

I have a

and like every self-respecting
, it is possible to hold on it and scroll it by moving the cursor ( also called caret ).
I'd like to know if there is a way to disable this feature ?


I based my answer using this post: http://stackoverflow.com/a/16586297/6611229 but I made changes to solve an issue. You can create a subclass of UITextField and add the following methods to the class:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
   self.selectedTextRange = [self textRangeFromPosition:self.endOfDocument

   return NO;

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