Ios 如何在UITextField上禁用保持和滚动
我有一个Ios 如何在UITextField上禁用保持和滚动,ios,uitextfield,Ios,Uitextfield,我有一个UITextField,就像每个自尊的UITextField一样,可以按住它并通过移动光标(也称为插入符号)滚动它。 我想知道是否有办法禁用此功能?我用这篇文章给出了我的答案:但我做了一些更改来解决一个问题。 您可以创建UITextField的子类,并将以下方法添加到该类中: - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { self.selectedTextRange = [self textRangeFro
UITextField
,就像每个自尊的UITextField
一样,可以按住它并通过移动光标(也称为插入符号)滚动它。
我想知道是否有办法禁用此功能?我用这篇文章给出了我的答案:但我做了一些更改来解决一个问题。 您可以创建UITextField的子类,并将以下方法添加到该类中:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
self.selectedTextRange = [self textRangeFromPosition:self.endOfDocument
toPosition:self.endOfDocument];
return NO;
}
- (CGRect)caretRectForPosition:(UITextPosition*)position
{
return [super caretRectForPosition:self.endOfDocument];
}
我的答案是基于这篇文章的:但是我做了一些改变来解决一个问题。 您可以创建UITextField的子类,并将以下方法添加到该类中:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
self.selectedTextRange = [self textRangeFromPosition:self.endOfDocument
toPosition:self.endOfDocument];
return NO;
}
- (CGRect)caretRectForPosition:(UITextPosition*)position
{
return [super caretRectForPosition:self.endOfDocument];
}