아, 알아 냈어. 텍스트보기는 예상대로 다른보기 안에 있지만 부모보기에서 사용자 지정 검색이있었습니다. In -hitTest : withEvent : 편집 모드에있는 경우 텍스트 뷰에서 hitTest를 호출하는 대신 텍스트 뷰 자체를 반환하므로 선택 뷰를 반환해야하는지 확인할 수 있습니다.
다른보기 내부에 텍스트보기가 있고 사용자 지정 검색을 수행하는 경우 선택 기능을 잃지 않도록 필요에 따라 UITextView에서 -hitTest : withEvent :를 호출해야합니다.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// a text box is tappable if:
// a) obviously, the tap point is inside self
// b) if current mode is unselected, check to see if a label was tapped. Because the label stretches the width of
// the text box for layout purposes, check to see if the tap point lays inside with intrinsic content size of the
// label. If not, pass the tap to the next subview
// c) If the mode is already selected, ask super to return the appropriate view.
if (!self.userInteractionEnabled || self.hidden || self.alpha <= 0.01) {
return nil;
}
CGRect touchRect = self.bounds;
if (self.currentMode == TextBoxModeSelected) {
touchRect = CGRectInset(self.bounds, -22, -22);
}
if (CGRectContainsPoint(touchRect, point)) {
if (self.currentMode == TextBoxModeUnselected) {
return [self.readOnlyTextView hitTest:point withEvent:event];
}
else if (self.currentMode == TextBoxModeSelected) {
return self;
}
else if (self.currentMode == TextBoxModeEdit) {
CGPoint pointInTextView = [self.editingTextView convertPoint:point fromView:self];
if ([self.editingTextView pointInside:pointInTextView withEvent:event]) {
// PREVIOUSLY I WAS RETURNING self.editingTextView HERE
// self.contentView IS THE TEXT VIEW'S PARENT. LET IT DETERMINE THE
// SUBVIEW THAT'S BEING TAPPED. IN THE CASE OF SELECTION, IT'S UITextRangeView
return [self.contentView hitTest:point withEvent:event];
}
}
}
return nil;
}