iOS 7 UITextView中的换行符打破了Text Kit排除区域换行

时间:2013-09-23 15:53:20

标签: objective-c ipad ios7 textkit

我正在使用iOS 7中的Text Kit,我发现NSTextContainer禁区周围有很多奇怪的地方。

我有两种观点:UITextView和简单的可拖动UIView;当UIView移动时,我会从UIView的框架创建一个贝塞尔曲线路径(调整到UITextView的坐标空间内)并更新UITextViewNSTextContainer的{​​{1}}数组 - 非常简单。

在第一个屏幕截图中,您可以看到Text Kit很好地将文本包裹在矩形排除区域周围:

Exclusion zone with no newlines in text

然而,当用户在exclusionPaths中引入换行符时,TextKit似乎认为禁区更垂直 - 看起来与换行符创建的空白一样高。 bezier路径完全相同,所以这似乎是一个Text Kit问题(除非我做错了)。

Exclusion zone with newlines in text

代码:

ViewController.h:

UITextView

ViewController.m:

@interface ViewController : UIViewController<UITextViewDelegate>

@property (nonatomic, strong) IBOutlet UITextView *textView;
@property (nonatomic, strong) IBOutlet UIView *dragView;

@end

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

我今天遇到了同样的问题。

如果您同时设置editableselectable,则似乎会出现此错误。如果仅选择一个或否,则按预期呈现。两者都是默认选中的。

enter image description here
enter image description here

如果您需要两个选项,只需在代码中设置它们。

_textView.textContainer.exclusionPaths = exclusionPaths;
_textView.attributedText = attrString;
_textView.editable = YES;
_textView.selectable = YES;