在UITextview当被按下的时间越长放大镜触摸显示出来.我怎么能禁用它.
我有一个使用故事板构建的UITextField.我想不允许用户更改光标的位置,并将其始终保留在文本末尾的文本字段中.
我尝试在触地事件中更改光标的位置,但是当选择文本字段然后再次触摸文本字段来更改光标的位置时,位置会更改:
- (IBAction)amountBoxTouchDown:(id)sender {
UITextPosition *start = [amountBox positionFromPosition:[amountBox beginningOfDocument] offset:amountBox.text.length];
UITextPosition *end = [amountBox positionFromPosition:start
offset:0];
[amountBox setSelectedTextRange:[amountBox textRangeFromPosition:start toPosition:end]];
}
Run Code Online (Sandbox Code Playgroud)
有谁知道解决方案?谢谢
我使用 UITextField 是因为我想要一个自定义的弹出式键盘。但是,我不希望用户能够更改插入点或访问复制、粘贴菜单。
我发现了两个有用的 stackoverflow 问题,并尝试实现它们:
我通过继承 UITextField 并实现方法删除了菜单:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
但是,当用户双击该字段时,我未能阻止该字段被选中:
我曾尝试删除我认为对选择行为负责的手势识别器,但没有成功。那么我做错了什么?
@property (nonatomic, strong) MinimalTextField *inputText;
...
@synthesize inputText;
...
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
NSLog(@"%ld gestureRecognizers initially ", (long)inputText.gestureRecognizers.count);
for (UIGestureRecognizer *gestureRecognizer in inputText.gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tapGestureRecognizer = (UITapGestureRecognizer *)gestureRecognizer;
if ([tapGestureRecognizer numberOfTapsRequired] == 2) {
NSLog(@"found & removed: %@", tapGestureRecognizer);
[inputText removeGestureRecognizer:tapGestureRecognizer];
}
}
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) …Run Code Online (Sandbox Code Playgroud)