Судя по указанию по умолчанию для распознавателя жестов двойного касания selectAll:
, вызывается для обработки текста. Аналогичным образом вы можете заставить свое текстовое представление выбрать текст при распознавании вашего единственного распознавателя жестов, используя selectAll:
в существующем методе tapTextViewGesture:
(как описано в вашем комментарии).
Если вы хотите, чтобы текст опции, чтобы показать автоматически, как они делают в ответ по умолчанию двойное нажатие жест распознаватель на (т.е. вырезание, копирование, вставка и т.д.), установите selectAll:
в self
:
- (IBAction)tapTextViewGesture:(id)sender {
[self.textView selectAll:self];
}
В противном случае , просто выделите текст без отображения меню, установите его в nil
:
- (IBAction)tapTextViewGesture:(id)sender {
[self.textView selectAll:nil];
}
Обновлено
Как указано OP в комментариях, распознаватель двойного касания UITextView
изначально только приводит к выбору одного абзаца.
Во-первых, откройте меню редактирования из текущей позиции курсора:
// Access the application's shared menu
UIMenuController *menu = [UIMenuController sharedMenuController];
// Calculate the cursor's position within the superview
// and convert it to a CGRect
CGPoint cursorPosition = [self.textView caretRectForPosition:self.textView.selectedTextRange.start].origin;
CGPoint cursorPositionInView = [self.textView convertPoint:cursorPosition toView:self.view];
CGRect menuRect = CGRectMake(cursorPositionInView.x, cursorPositionInView.y, 0, 0);
// Show the menu from the cursor's position
[menu setTargetRect:menuRect inView:self.view];
[menu setMenuVisible:YES animated:YES];
Затем выберите текущий абзац, вот что я рекомендую:
// Break the text into components separated by the newline character
NSArray *paragraphs = [self.textView.text componentsSeparatedByString:@"\n"];
// Keep a tally of the paragraph character count
int characterCount = 0;
// Go through each paragraph
for (NSString *paragraph in paragraphs) {
// If the total number of characters up to the end
// of the current paragraph is greater than or
// equal to the start of the textView's selected
// range, select the most recent paragraph and break
// from the loop
if (characterCount + paragraph.length >= self.textView.selectedRange.location) {
[self.textView setSelectedRange:NSMakeRange(characterCount, paragraph.length)];
break;
}
// Increment the character count by adding the current
// paragraph length + 1 to account for the newline character
characterCount += paragraph.length + 1;
}
Вы уже настроили индивидуальный жест выделения и связанный с ним метод? –
Да, '- (IBAction) tapTextViewGesture: (id) отправитель { NSLog (@" TAP "); } ' – Adelmaer