我有一个在右下角有UIButton的UITextView。我的UITextView允许多行文本,即textView高度在键入enter键时动态增加(类似于短信应用程序)。但我的问题是,在输入文本时,文本会被放在UIButton后面。我希望文本在到达图像时停止,并在下一行继续,文本中没有任何中断。这个是可能的吗?

发布于 2016-04-30 17:54:38
这个解决方案对我很有效。我有UItextview的子类,我把这段代码放在那里。
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:_buttonClear.frame];
self.textContainer.exclusionPaths = @[exclusionPath];发布于 2016-04-30 15:37:12
使用苹果公司提供的Text Kit Framework。你可以做到这一点
这是ray wenderlich tut https://www.raywenderlich.com/50151/text-kit-tutorial
具体地说,您必须为UITextView设置exclusionPaths
UIBezierPath* exclusionPath = [_timeView curvePathWithOrigin:myButton.center];
_textView.textContainer.exclusionPaths = @[exclusionPath];发布于 2016-04-30 19:31:41
试试下面的代码:
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:Button.frame];
self.textContainer.exclusionPaths = @[exclusionPath];使用UITextView委托并执行以下操作:
- (void)textViewDidChange:(UITextView *)textView
{
//Get Buttons Y position and Allow TextView Frame changes until it is less than or equal buttons Y position
if (textView.frame.origin.y+textView.frame.size.height < Button.frame.origin.y) {
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
}
}https://stackoverflow.com/questions/36952127
复制相似问题