Я использовал успешный обходной путь, но это было больно. Это процесс, которому я следовал:
- Откройте XIB в текстовом редакторе
- Найдите нарушителя
TextView
. В моем случае:
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="782-j1-88c" customClass="LCAnsiConsoleTextView">
<rect key="frame" x="16" y="20" width="343" height="589"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="12"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
Обратите внимание на
id
(в моем случае:
id="782-j1-88c"
) Переопределите класс, как отмечено в ответах выше, и воссоздайте параметры (у меня Objective-C, извините):
@implementation FixedTextView
- (id) initWithCoder:(NSCoder*)coder
{
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){13,2,0}])
self = [super initWithCoder:coder];
else {
self = [super initWithFrame:CGRectMake(16, 3, 343, 605)];
self.editable = YES;
self.selectable = YES;
self.insetsLayoutMarginsFromSafeArea = YES;
self.clipsToBounds = YES;
self.clearsContextBeforeDrawing = YES;
self.autoresizesSubviews = YES;
self.contentMode = UIViewContentModeScaleToFill;
self.scrollEnabled = YES;
self.userInteractionEnabled = YES;
self.multipleTouchEnabled = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;
self.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0];
}
return self;
}
Обратите внимание на ограничения, которые включают в себя ваш идентификатор текстового представления, и воссоздайте эти ограничения для других идентификаторов элементов в вашем представлении или контроллере представления. В моем случае:
- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self xibSetup];
[self initView];
/*
<constraint firstItem="75C-lt-YtE" firstAttribute="top" secondItem="782-j1-88c" secondAttribute="bottom" constant="8" symbolic="YES" id="8SH-5l-FAs"/>
<constraint firstItem="782-j1-88c" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leadingMargin" id="Mve-aZ-HCe"/>
<constraint firstItem="782-j1-88c" firstAttribute="leading" secondItem="75C-lt-YtE" secondAttribute="leading" id="dPG-u3-cCi"/>
<constraint firstItem="782-j1-88c" firstAttribute="trailing" secondItem="iN0-l3-epB" secondAttribute="trailingMargin" id="sjT-0Q-hNj"/>
<constraint firstItem="782-j1-88c" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="vic-vZ-osR"/>
*/
[self.command.topAnchor constraintEqualToAnchor:self.console.bottomAnchor constant:8].active = YES;
[self.console.leadingAnchor constraintEqualToAnchor:self.layoutMarginsGuide.leadingAnchor].active = YES;
[self.console.leadingAnchor constraintEqualToAnchor:self.command.leadingAnchor].active = YES;
[self.console.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = YES;
[self.console.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor].active = YES;
}
return self;
}
Это исправило проблему для меня без потери желаемой функциональности. К счастью, у меня был только один UITextView
для замены. В противном случае это становится несостоятельным.