Ios 在UITextView';文本容器集
在我的应用程序中,我使用屏幕顶部的自定义工具栏(只是另一个Ios 在UITextView';文本容器集,ios,uiview,autolayout,uitextview,animatewithduration,Ios,Uiview,Autolayout,Uitextview,Animatewithduration,在我的应用程序中,我使用屏幕顶部的自定义工具栏(只是另一个UIView);它位于UITextView上方。我正在使用自动布局 因为我正在使用此自定义工具栏,所以我正在执行以下操作,以使UITextView在页边距和滚动指示器方面看起来正确: // the height of the custom toolbar is 55 _textView.textContainerInset = UIEdgeInsetsMake(68, 5, 8, 5); _textView.scrollIndicator
UIView
);它位于UITextView
上方。我正在使用自动布局
因为我正在使用此自定义工具栏,所以我正在执行以下操作,以使UITextView
在页边距和滚动指示器方面看起来正确:
// the height of the custom toolbar is 55
_textView.textContainerInset = UIEdgeInsetsMake(68, 5, 8, 5);
_textView.scrollIndicatorInsets = UIEdgeInsetsMake(54, 0, 0, 0);
当显示键盘时,我将删除工具栏。当键盘关闭时,我显示工具栏。我设置工具栏位置更改的动画,如下所示:
- (void)animateTopToolbarOn
{
[self.view removeConstraints:_topToolbarOffScreenVerticalConstraints];
[self.view addConstraints:_topToolbarOnScreenVerticalConstraints];
[UIView animateWithDuration:0.6 animations:^{
[self.view layoutIfNeeded];
}];
// this is the bit I need to get right:
_textView.textContainerInset = UIEdgeInsetsMake(68, 5, 8, 5);
_textView.scrollIndicatorInsets = UIEdgeInsetsMake(54, 0, 0, 0);
}
- (void)animateTopToolbarOff
{
[self.view removeConstraints:_topToolbarOnScreenVerticalConstraints];
[self.view addConstraints:_topToolbarOffScreenVerticalConstraints];
[UIView animateWithDuration:0.6 animations:^{
[self.view layoutIfNeeded];
}];
// this is the bit I need to get right:
_textView.textContainerInset = UIEdgeInsetsMake(8, 5, 8, 5);
_textView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
}
// For reference:
id topGuide = self.topLayoutGuide;
_topToolbarOffScreenVerticalConstraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:[_topToolbar][topGuide]"
options:0
metrics:nil
views:views];
_topToolbarOnScreenVerticalConstraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:[topGuide][_topToolbar]"
options:0
metrics:nil
views:views];
工具栏位置/约束的动画效果很好,正如您所期望的那样
问题在于更改textContainerInset
的值
注意:我知道我可以将更改放在动画的完成块中。虽然它会改变它的外观/感觉,但问题仍然存在,顶部边距的变化会立即发生,因此它看起来像一个跳转。很刺耳
我可以将UITextView
的顶部约束锚定到工具栏的底部约束;这样,我就不需要更改textContainerInset
值或滚动指示器集。但是,如果我这样做,文本将不会在工具栏下方滚动。如果可能的话,我想避免这种退路
有什么想法吗
我不认为textContainerInset
的值可以设置动画?它与
如何使用普通的UIView
作为自定义工具栏来实现此设置,该工具栏在屏幕上和屏幕下都会显示动画,UITextView
的边距会对其做出响应?这方面有何进展?不是我自己做的-我没有对此做任何更改。我认为,由于textContainerInset
的值无法设置动画,因此我必须在上面描述的限制范围内工作;但是,此链接似乎表明您确实可以设置UIEdgeInset
更改的动画:。所以,我想知道这是否是UITextView
的特殊功能。我试着用它的layoutManager
和textContainer
混日子,但那也不行,我打电话给layoutfneed
。