Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UITextField上禁用保持和滚动_Ios_Uitextfield - Fatal编程技术网

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];
}